Building a Swift Framework with Xcode 7 (Beta 3) to use as an Embedded Binary
Ever since Embedded Binaries were introduced in iOS 8, I have been wanting to port a lot of my common code into frameworks. I decided to wait one year before doing it and this year, with Xcode 7 Beta and iOS 9, I’m starting to do that just that.
I have started a Cocoa Touch framework project in Xcode 7 and I want to compile it into a usable framework. I can get it to compile my project into a .framework, but there’s a few issues; namely, the framework doesn’t appear to be importable into new projects (I will describe the steps I did for that shortly). Because of that, I’m not sure if my framework has any visible symbols.
This is what I have done to create the Framework:
- Created my Framework as a Cocoa Touch Framework.
- Went to my target’s Build Phases, went to Headers, and added all my Swift files to the “Public” section, in hopes that will export all my simbols without having to mark them as
- I tried to archive my project as a framework. Currently, it looks like Xcode 7 Beta 3 has a bug (going to report it later today) in which it generates corrupted archive files. For this reason I couldn’t get my framework from the Organizer Window. To work around this, I changed the schema of the Run action in Xcode from Debug to Release, built it and grabbed it’s generated
.frameworkfrom my project’s
build/iphoneos-releasedirectory. This was a quick test so I didn’t need the frameworks generated for emulators.
And this is what I did to try to add the framework to a new project:
- Created a “Frameworks” group (for organizational purposes) and dragged the framework there, selecting “yes” when it asked me if I want to copy the file to my project’s directory.
- Went to my target’s settings, removed my framework from “Linked Libraries” (it was added there automatically), added it to Embedded Binaries instead. This added the framework to Linked Libraries again, so I had to remove it from there twice. Leaving the framework in Linked Libraries causes a linker error (can’t find the framework – no idea why but I think it’s irrelevant to my problem and something I should report to Apple as well), but once you remove it from there it seems to compile fine when you add it to Embedded Binaries.
- Tried to import my framework in a file. Xcode complains there is “no such module”.
Unfortunately, despite the fact that embedded frameworks have been around for around a year, I can’t find much writing on the topic.
So my question is: Am I creating the framework correctly, making it possible that my framework/anything else is failing due to an Xcode 7 Beta bug? Or is there a different procedure to create a framework that I want to use as an Embedded Binary? I should probably mention that I want to make this library open source, and I think distributing a plain
.framework file to the people who want to use it would be neat.
Solutions Collect From Internet About “Building a Swift Framework with Xcode 7 (Beta 3) to use as an Embedded Binary”
I Had the same issue on Xcode 7.
I solved it by editing the build settings of the project (the one which includes the framework).
By setting the Framework Search Paths field to $(PROJECT_DIR) or to the path to the directory that contains the .framework file it should help Xcode finding the module.
- Slider with real time in Label
- Trying to get network error alert to show on iPhone app?
- How do I add a third party Framework to iPhone project?
- Will iOS region monitoring call didEnterRegion on my app if my app is in a terminated state?
- sqlite3_prepare_v2 exc_bad_access in iOS 10
- IOS: Using A Pattern Image As A Background -Memory Leak
- Swift 1.2 error on Objective-C protocol using getter
- Attempting to delete an image from Xcode 4
- iOS: how to reduce size of large PNG files
- Can't get C++14 using XCode 7.0.1
- What is the best way to sort a Core Data Entity?
- How to get device make and model on iOS?
- Live555 framework generation error
- UINavigationItem Back Button touch area too large
- LibXML2.dylib with Xcode6