The way I did it is similar to vladof, but hopefully a little simpler. I made the framework a subproject of the app project.
Framework project
- Create a new iOS Cocoa Touch Framework. Call it MyLib. This will create a single MyLib.h
- Add a simple Cocoa Touch Obj-C class, MyClass (.h & .m) and in the implementation of the .m, create a method that returns a string, - (NSString *)greetings;
- In MyLib.h, add this near the bottom, #import "MyClass.h"
- In the target's Build Phases/Headers section, Move MyClass.h from the Project section to the Public section.
- Do a Build (cmd-B)
- Close the the project
App project
- Create a new Single View application project, either Swift or Obj-C. Call it MyApp.
- From the Finder, drag your MyLib project file to the left hand organizer section of you MyApp window and make sure the insertion line is just below MyApp. This makes MyLib a subproject of MyApp. (It can still be used the same way in other projects)
- Click on MyApp in the organizer and then select the MyApp target and select Build Phases.
- In Target Dependancies, click the + sign and add MyLib.
- In Link with Libraries, click the + sign and add MyLib.framework.
For an Obj-C app
- In ViewController.m, add #import
- In viewDidLoad, add the following lines:
- MyLib *x = [[MyLib alloc] init];
- NSLog(@"%@", x.greetings);
- Run the project and you should see the message in the debug window. -
For a Swift app
- In ViewController.swift, add import MyLib
- in viewDidLoad, add the following lines:
- var x: MyLib = MyLib()
- println("(x.greetings())") -
By doing it this way, the app is dependent on the framework so if you make a change in the framework classes, you don't have to change targets to build the framework separately, it will just compile the framework first, then the app.