How to embed private Objective-C framework into iOS app on Xcode 6 with workspaces

强颜欢笑 提交于 2019-12-11 03:22:29

问题


I have written a small private framework that I want to share between a few iOS apps.

Here is the work flow I envision:

  1. Pull SimpleApp from source control.
  2. Pull BobFramework from source control.
  3. Somehow embed BobFramework into SimpleApp using Xcode.
  4. Build project.
  5. 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:

  1. Import Newhart.h in BobLib.h #import <BobLib/Newhart.h>
  2. Designated Newhart.h as public.
    1. Selecting Newhart.h in Project Navigator.
    2. In Utilities Area | File Inspector | Target Membership change "Project" to "Public".
  3. Build BobLib for both Simulator and Device.
  4. Control-click BobLib.framework and select Show in Finder.
  5. Open Sandbox2 in Xcode.
  6. Drag BobLib.framework from Finder window to Pen1.
  7. Project | Target | General | Embedded Binaries, add BobLib.framework.
  8. BobLib.framework should already be in Project | Target | General | Linked Frameworks and Libraries.
  9. Run and test app. It should be able to call doThatThing in Newhart instance.
  10. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!