Michael Peterson
Michael Peterson

Reputation: 10532

Error building Swift Cocoa Touch Framework after adding Swift file: <unknown>:0: error: could not build Objective-C module

I have a problem creating a Swift Cocoa Touch Framework. As soon as I add my first .swift file, clean, then build I get a build error:

<unknown>:0: error: could not build Objective-C module 'MyTextFramework'

This is easily reproducible from scratch in just a few steps using Xcode 6.1.1

I've tried the typical Xcode magic such as deleting derived data, restarting Xcode, etc.


Steps detailed below with screenshots:

File > New > Project > iOS Framework & Library > Cocoa Touch Framework enter image description here

Product Name: MyTextFramework

Language: Swift enter image description here

I now have a bare bones Cocoa Touch Framework. enter image description here

Add an iOS Swift file named FooBaz.swift

Add a class that extends NSObject and an init function.

The target still builds fine at this point. enter image description here

Cmd-K to clean the project

Cmd-B to build again... BAM enter image description here

Upvotes: 4

Views: 1057

Answers (2)

Michael Peterson
Michael Peterson

Reputation: 10532

As Georg Tuparev answered, I just need to remove MyTextFramework.h and it builds fine. However, this prevents using my framework in Obj-C code.

Is it even possible to build a framework containing Swift code that can be used in both Swift AND Obj-C? If it is technically possible, then it seems this issue with Xcode would prevent anyone from actually doing it. Does anyone have any comments or solutions for this scenario?

Upvotes: 1

Georg Tuparev
Georg Tuparev

Reputation: 441

If you are not going to use this Swift framework from Objective-C, the easiest solution is to get rid of MyTextFramework.h

Upvotes: 3

Related Questions