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
- Access control, Swift has three level of access control. Just follow when creating your own framework.
- Public, code called by other framework or the app.
- Internal, code called within the framework.
- Fileprivate, the code called within a single file.
- Private, code called within a single class, even it won’t be visible in extension of the class
- Sometimes when you integrate framework it gives a crash while launching “framework not found” then simply clean or restart the Xcode works.
- If you want to include the storyboard within the framework then make sure you are accessing it using Bundle with an identifier.
- 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.
- Enable the check `Always Embed Swift Standard Libraries` will give you the flexibility to use it with lower Swift versions.
- 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!!!