问题
I have written a small private framework that I want to share between a few iOS apps.
Here is the work flow I envision:
- Pull SimpleApp from source control.
- Pull BobFramework from source control.
- Somehow embed BobFramework into SimpleApp using Xcode.
- Build project.
- Done!
The problem is how do I accomplish the "embed using Xcode" step?
I cannot find step-by-step instructions on how to do this. Apple's docs are an out-of-date lie.
All the Stack Overflow questions I have found assume readers know the overall procedure, and I cannot gather enough contextual clues to fill in the implied steps. In fact, I would say a lot of questions stem from the fact there is no modern published procedure from Apple and thus a lot of people are following implied or guessed-at steps.
The most direct, simple, complete, and up-to-date set of steps I have found applies mainly to Swift. The procedure for Swift is sensible, and I wish I was using it, but I am using Objective-C.
I have tried several experiments based on what I am guessing the procedure is, but there are so many possibilities of what the correct procedure could be, that I do not think posting one of my specific problems is the proper approach at this time. After all, everything I have done leading up to my problem could be incorrect.
回答1:
It took me a while to figure this out, but I did. I posted a more elaborate answer on my blog with several screen shots.
Now to condense that answer down for Stack Overflow. I will explain by example recipe.
Starting point:
- Workspace named SandBox2 with project named Pen1.
- BobLib is name of framework in its own project.
- Created by File | New | Project, iOS | Framework & Library | Cocoa Touch Framework.
- In separate project to simulate my particular situation. If you get the chance, you should probably just start with the framework already part of workspace.
- Header file Newhart.h contains
doThatThing
method declaration.
Goal: ViewController in Pen1 calls doThatThing
on instance of Newhart class.
Steps:
- Import Newhart.h in BobLib.h
#import <BobLib/Newhart.h>
- Designated Newhart.h as public.
- Selecting Newhart.h in Project Navigator.
- In Utilities Area | File Inspector | Target Membership change "Project" to "Public".
- Build BobLib for both Simulator and Device.
- Control-click BobLib.framework and select Show in Finder.
- Open Sandbox2 in Xcode.
- Drag BobLib.framework from Finder window to Pen1.
- Project | Target | General | Embedded Binaries, add BobLib.framework.
- BobLib.framework should already be in Project | Target | General | Linked Frameworks and Libraries.
- Run and test app. It should be able to call
doThatThing
in Newhart instance. - This only works for iOS 8 or higher.
来源:https://stackoverflow.com/questions/28304263/how-to-embed-private-objective-c-framework-into-ios-app-on-xcode-6-with-workspac