0
votes

I have a swift executable package that has a dependency on objective-c library package. I'm trying to use Xcode for executable package development but I'm getting Could not build Objective-C module 'objcpackage' error while editing the swift file which imports objective-c module. Compiling works both from Xcode and also directly from command line using swift build but as soon as I open the swift file with import of that objc package the error pops up. I have used the SPM to generate xcodeproj.

Clean nor clean build directory, deleting generated module map from the xcodeproj or restarting Xcode did not help.

I have created Objective-C package with the following:

$ swift package init --type library

It contains only one header Sources/include/Foo.h:

#import <Foundation/Foundation.h>

@interface Foo: NSObject
@end

and one .m file:

#import "Foo.h"

@implementation Foo
@end

The Swift package was created with $ swift package init --type executable.

The Package.swift file looks like:

import PackageDescription

let package = Package(
    name: "swiftpackage", 
    dependencies: [ .Package(url: "../objcpackage", majorVersion: 1) ]
)

The main.swift contains only:

import objcpackage

Xcode project was created with $ swift package generate-xcodeproj

Xcode Version: 8.2.1 (8C1002)

Swift Version: 3.0.2 (swiftlang-800.0.63 clang-800.0.42.1)

How can I get rid of that error?

1

1 Answers

1
votes

This sounds like a bug that was recently fixed in the package manager (https://bugs.swift.org/browse/SR-3121). Have you tried a recent snapshot from https://swift.org/download/?

I tested the package you describe with a recent version of Swift 3.1 and it worked fine.