1

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 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! With latest snapshot (3.1-dev (LLVM a7c680da51, Clang df9f12fda6, Swift 7cc03a3925)) the error is gone.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.