Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

  • Create new Cocoa Touch Framework using Swift Language
  • Add an iOS swift file
  • Build - OK
  • Clean - OK
  • Build - ERROR
  • From here on the project will not build unless I delete the swift file.

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

like image 598
Michael Peterson Avatar asked Oct 15 '25 10:10

Michael Peterson


1 Answers

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

like image 130
Georg Tuparev Avatar answered Oct 17 '25 04:10

Georg Tuparev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!