Swift Framework creation

Swift Language

Swift Framework creation

This is my preferred way to set up a Swift framework project.


Sometimes, you will find yourself using the same custom code in multiple projects. Simply copying the files into a new project works, but then you have different versions. So, a better way to reuse that code is to create a Framework.

This is my preferred way.There are other ways that The Google will show you. I had luck with none of them – especially at link time. One example has you dragging the framework from the simulator’s temp directory via the Finder. Yikes.

Without a workspace, iterative development on the framework and a potential client of it will be awkward. So, I suggest creating a workspace and adding the framework project to it along with at least one app project that uses the framework.

Table of Contents

Creating the projects

You will create a framework, a Single Page App that uses it, and a workspace to make your life easier.

Create a Single Page App.

Close it.

Create a Framework.

Close it.

Create a Workspace.

Choose Add Files (⌥ ⌘-A or right click or choose from the File Menu).
Add the .xcodeproj files for your framework and your app to the workspace.

If you didn’t close your framework project or your app, it will not be added correctly. You will see just your .xcodeproj file and not the project.

You should see something like this in your project navigator.


Table of Contents


Click on your Framework project.
For the scheme, make certain that your framework is selected and then choose IOS Device.
Like this:

Build the framework. (⌘-B)
Open up Products and MyFrameework.framework should not be red anymore but black.

Now select your App and choose the General tab for the app target.
Drag MyFrameework.framework to “Embedded Binaries”
Notice that Linked frameworks and Libraries also picks this up.

You’re ready!

Table of Contents

A Framework Class

Create a class in your framework. Be certain that the class and the function your will be calling are both public. If you define init functions, then they also need to be public.

Build (⌘-B)

Table of Contents

Try it out

For a simple test, open your view controller. You need to import your framework. If you named it MyFramework, simply specify MyFramework.

Now use your class from the framework. When you build, check the scheme to make sure you’re building the app and not the framework!

It’s fairly simple to go back to the framework, add classes and modify them, build, then go back to the app and try them out.

Table of Contents


Create a framework, an app that uses it, then add both projects to a workspace.
Build the framework, then drag the framework product to “Embedded Binaries” on the general tab of your app’s target.


Share These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Facebook
  • Twitter
  • LinkedIn
  • email
  • DZone
  • Slashdot
  • Reddit
  • Google Bookmarks
  • Digg
  • StumbleUpon
  • del.icio.us
This entry was posted in Swift and tagged , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.


  1. Posted May 20, 2015 at 8:10 am | Permalink

    Thanks for this tutorial, I found it to be the best source of information available to get my framework and application up and running.

  2. Jen
    Posted July 5, 2015 at 10:13 am | Permalink

    This tutorial looked promising but it didn’t work for me. I’m using xcode 6.4 and the class that is shared via the framework is not visible to the test framework project. Would you be able to share the source so I can give it a run?

    • Bob
      Posted October 28, 2015 at 11:46 am | Permalink

      Same here. It’s absolutely impossible. I have tried to get my framework Swift classes (which are supposed to have auto-generated headers in the framework) revealed to the project I’m using the framework in and it’s absolutely impossible. Not a single guide online can help me. Please let me know if you figured it out.

      • Dan
        Posted April 17, 2016 at 10:20 am | Permalink

        You may be forgetting to make the Swift classes you are trying to use public. The compiler does not give very good hints about the classes you are trying to use being available but not accessible.

        Once I followed the above steps and made the Swift class I was trying to use public – as well as making a public initializer – public init() {} – the whole thing worked as I expected.

  3. Mark
    Posted November 1, 2015 at 9:26 am | Permalink

    Thanks for your great tutorial, it was esencial for me for understanding Frameworks. But only one thing more, in Swift 7.1 is not necessary “Now select your App and choose the General tab for the app target. Drag MyFrameework.framework to “Embedded Binaries”. In fact the Products remaining in red but it works !!!

  4. Jeremy
    Posted November 20, 2015 at 8:15 pm | Permalink

    Terrific! Stuff like this always seems to be under documented.

  5. wcchang.hh
    Posted November 25, 2015 at 2:44 am | Permalink

    Thanks for your great tutorial.

    How about the other app to use our framework? Do they have to take the source/project code of our framework into their workspace and build for work, too?
    I can not find a way to just share “MyFramework.framework” to other app, can we?

Post a Comment

Your email is never published nor shared.

You may use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">