Framework


Some notes on swift .framework

Export:

  1. Xcode -> New project -> Cocoa framework
  2. Add .swift files to your framework
  3. cmd + b (aka build)

If you want to build your framework along side your normal XCode project:

  1. Save as target -> pick Cocoa framework
  2. Select .swift files and set their target membership to the .framework
  3. cmd + b (aka build)

Import:

  1. Right click on the ‘.framework’ and select ‘Show in Finder’
  2. copy the .framework file in the same folder where your .swift files are. Then drag it into Xcode.
  3. In your new project: Project settings -> General -> Embedded binaries add the .framework via the + button🔑

Access level:

Swift has three levels of access control. Use the following rules of thumb when creating your own frameworks:

  • Public: for code called by the app or other frameworks, e.g., a custom view.
  • Internal: for code used between functions and classes within the framework, e.g., custom layers in that view.
  • Fileprivate: for code used within a single file, e.g., a helper function that computes layout heights.
  • Private: for code used within an enclosing declaration, such as a single class block. Private code will not be visible to other blocks, such as extensions of that class, even in the same file, e.g., private variables, setters, or helper sub-functions.
  • @testable if you prefix your import with @testable then you can work with framework classes even if they are not marked public 🔑

Resources:

  • Make a framework of your swift files in a xcode project. And also add playground that can import the framework: here
  • Use the a .framework file in other projects by copying it: here
  • Export and Drag and drop .framework to different projects: here
  • Nice video here

NOTES:

  • Apple claims that its best to use less than 6 .frameworks in your app. Or else compile time may suffer
  • Dynamic frameworks supported after ios 8 on iOS. Dynamic frameworks are linked form your app, static frameworks are included in the app.

Related Posts

Startup Oslo

“Kulturhuset” is a new place in the startup scene in Oslo. It’s “free” and can be used by anyone to collaborate or work on different projects.

Infinite Tree List

My notes on Infinite tree list

Protocol Inheritance

My notes on Protocol Inheritance

Protocol Ambiguity

How to differentiate protocol ambiguity

The Ultimate Xcode Workflow

Spend zero time managing dependencies

Faster Xcode With Spm

How you can speed up compile times in XCode with Swift Package Manager

Spm And Ci Travis

My notes on Swift PM + CI Travis

Spm And Nested Frameworks

My notes on Swift package manager + XCode + Nested frameworks

Xcode And Spm

Here is how you use Swift package manager in your XCode app projects

Carthage And Nested Frameworks

A few workflows concerning Carthage and nested framework