It is a sample project, that shows how to create and use frameworks in Swift, Objective-C and mixed projects.
Short recap: Frameworks are just dynamic libraries, that are wrapped in a bundle and have some additional resources
It consists of a client app (Libs & Frameworks Showcase
target) and several types of libraries:
- Framework in Swift
- Framework in Objective-C
- Framework in Swift and Objective-C
The client application has 2 classes, that make use of all the libraries: a Swift class SwiftDependenciesClient
and an Objective-C class ObjectiveCDependenciesClient
. So you can see how to import any type of library in client app, and the languages don't matter here.
- Add a new Framework target (choose Swift language).
- Add .swift files to the new target.
- Remember, only
open
andpublic
types are visible outside the module. - Import the framework in the swift file, where you need it (
import SwiftFramework
). - Import it in Objective-C file via
@import SwiftFramework;
- Use it!
- Add a new Framework target (choose any language)
- Add .swift files
- Add .h and .m files
- Import the headers in the umbrella header of the framework (
SwiftObjectiveCFramework.h
in our project):
#import <SwiftObjectiveCFramework/OBJSwiftObjectiveCFrameworkClass.h>
- Remember, that only open and public Swift declarations are visible outside the module.
- Import the module in the Swift or Objective-C files of the client app.
- Add a new Framework target (choose Objective-C language).
- Add some classes.
- Import the headers in the umbrella header of the framework (
ObjectiveCFramework.h
in our project):
#import <ObjectiveCFramework/ObjectiveCFrameworkClass.h>
- Import the module in the Swift or Objective-C files of the client app.