Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Building pure Swift Cocoa Touch Framework

I'm exploring Swift with Xcode-6 and so far so good although I think the new collections need a little bit of work as I've managed to break the compiler a few times.

Problem is I'm now stuck trying to create the framework package to then use in another project. The project builds without issue and all tests pass successfully. When I go to create Archive (which I assume is what is required) I receive the error:

:0: error: underlying Objective-C module 'Sample' not found

Now I assume this has something to do with the contents of my Sample.h which tells me

// In this header, you should import all the public headers of your framework using statements like #import <Sample/PublicHeader.h> 

which is fine except I have only used swift enums, structs and classes for this framework so therefore no .h files exist.

Can anyone shed some light on this one as I can't find any documentation available yet?

like image 405
Moth Avatar asked Jun 05 '14 21:06

Moth


People also ask

What is Cocoa framework in Swift?

Cocoa is an application environment for both the OS X operating system and iOS, the operating system used on Multi-Touch devices such as iPhone, iPad, and iPod touch. It consists of a suite of object-oriented software libraries, a runtime system, and an integrated development environment.

What is the difference between Cocoa Touch class and swift file?

There is no difference between the two different templates other than the code they put into the file by default. Like you noticed, they both have the same extension and they are both plain text files – the compiler does not treat them any differently.

Is Cocoa Touch framework?

Cocoa and Cocoa Touch are the application development environments for OS X and iOS, respectively. Both Cocoa and Cocoa Touch include the Objective-C runtime and two core frameworks: Cocoa, which includes the Foundation and AppKit frameworks, is used for developing applications that run on OS X.


2 Answers

EDIT (7/27/2018)

The information in the answer below may no longer be accurate. Your mileage may vary.


I sat down with an engineer and asked this exact question. This was their response:

Xcode 6 does not support building distributable Swift frameworks at this time and that Apple likely won't build this functionality into Xcode until its advantageous for them to do so. Right now, Frameworks are meant to be embedded in your app's project, rather than distributed. If you watch any of the session videos or see the sample projects, this is always the arrangement. Another reason is that Swift is very new and likely to change. Thus your Swift-based framework is not guaranteed to work on the platform you originally built it on.

Slight Update

The engineer mentioned that it's not impossible to make a framework for distribution, just that it's not supported.

like image 198
Aaron Avatar answered Sep 28 '22 10:09

Aaron


I was able to get past the error by going to the target for the framework and on the Build Phases tab under Headers, remove the MyFramework.h file

However I was getting the "Underlying Objective-C module not found" error when I was using a framework to share code between a containing app and an app extension, both of which were pure Swift.

Image showing MyFramework.h for the MyFramework target on the Build Phases tab under Headers

like image 32
Jamie McDaniel Avatar answered Sep 28 '22 09:09

Jamie McDaniel