Creating and distributing iOS frameworks | Swift | Quick Notes

Do you want to share your code with other apps or may be other developers or perhaps you want to distribute your code in the same way as popular 3rd parties do?

Frameworks have three major purposes.

  • Encapsulation of Code
  • Modularity of Code
  • Reusability of Code

Open Xcode, select Cocoa Touch Framework, give meta data about your framework, Just drag and drop the files you want to add and here we going just build it and share the framework with other developers etc.


Points need to take care

  1. Access control, Swift has three level of access control. Just follow when creating your own framework.
    1. Public, code called by other framework or the app.
    2. Internal, code called within the framework.
    3. Fileprivate, the code called within a single file.
    4. Private, code called within a single class, even it won’t be visible in extension of the class
  2. Sometimes when you integrate framework it gives a crash while launching “framework not found” then simply clean or restart the Xcode works.
  3. If you want to include the storyboard within the framework then make sure you are accessing it using Bundle with an identifier.
  4. Once build your framework generates file Framework-Swift.h (Framework/Headers/Framework-Swift.h) where you can see who all files will be publicly available to use.

  5. Enable the check `Always Embed Swift Standard Libraries` will give you the flexibility to use it with lower Swift versions.

  6. For best practice, add framework target within your working copy of the code, whenever wants to release just change the target and create the new framework.

    Thanks for Reading!!!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.