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

1

2

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.

Overbear answered 3/2, 2015 at 16:47 Comment(3)
Why not just use a second project file in your workspace?Kemppe
@IanMacDonald Step-by-step how? I've read dozens of one-line remarks that hint at pieces of answers. I want this question to document a complete answer because so far I have found none.Overbear
Step 1: Open Finder to the folder containing your BobFramework project. Step 2: Open Xcode with the workspace containing your SimpleApp project. Step 3: Drag the BobFramework project into the Project Navigator in Xcode to attach it to the same workspace as your SimpleApp.Kemppe
O
2

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.
Overbear answered 8/2, 2015 at 0:36 Comment(2)
In your blog you said to drag in the simulator product, not the device product, when you drag the framework to the app project. Why? Did you find docs about that somewhere? I ask because I'm having problems with different behavior in some cases, depending on whether I drag the simulator or device framework. It seems odd/buggy that I should have to redo this when I change from device to simulator.Dmz
@RobN I do not want to give useless reply, but also don't want to ignore you. Answer is: I don't recall precisely, but I've moved on to another solution. My memory says dynamic lib binaries must match platform: simulator or device. Maybe new Xcode 6.2 fixes this inconvenience? Maybe it is possible to add both?Overbear

© 2022 - 2024 — McMap. All rights reserved.