Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to install a custom cocoa framework

I have a custom framework that, following the advice in Apple's Framework Programming Guide >> Installing your framework I install in /Library/Frameworks. I do this by adding a Run Script build phase with the following script:

cp -R  build/Debug/MyFramework.framework /Library/Frameworks

In my projects I then link against /Library/Frameworks/MyFramework and import it in my classes like so:

#import <MyFramework/MyFramework.h>

This works very well, except that I always see the following message in my debugger console:

Loading program into debugger… sharedlibrary apply-load-rules all warning: Unable to read symbols for "/Users/elisevanlooij/Library/Frameworks/MyFramework.framework/Versions/A/MyFramework" (file not found). warning: Unable to read symbols from "MyFramework" (not yet mapped into memory). Program loaded.

Apparently, the compiler first looks in /Users/elisevanlooij/Library/Frameworks, can't find MyFramework, then looks in /Library/Frameworks, does find MyFramework and continues on its merry way. So far this has been more of an annoyance than a real problem, but when runnning unit tests, gdb stops on the (file not found) and refuses to continue. I have solved the problem by adding an extra line to the Run Script Phase

cp -R  build/Debug/MyFramework.framework ~/Library/Frameworks

but it feels like sello-taping something that shouldn't be broken in the first place. How can I fix this?

like image 835
Elise van Looij Avatar asked Nov 04 '09 17:11

Elise van Looij


People also ask

How do I archive framework in Xcode?

Start your archiveNavigate to your project's settings. Under iOS (or the target you want to build your app for) > Identity, you'll want to increment the Build number. For example, if the Build number was 1, you'll want to set it to 2. Then, in the top menu, under Product, click on Archive.

Is Swift a framework?

Swift is a multipurpose, multi-paradigm compiled language created by Apple Inc. It is used for macOS, iPadOS, iOS, watchOS, Linux, and tvOS. The team that developed it makes use of an open-source LLVM compiler framework.


1 Answers

In the past months, I've learned a lot more about frameworks, so I'm rewriting this answer. Please note that I'm talking about installing a framework as part of the development workflow.

The preferred location for installing a public framework (i.e. a framework that will be used by more than one of your apps or bundles) is /Library/Frameworks[link text] because "frameworks in this location are discovered automatically by the compiler at compile time and the dynamic linker at runtime."[Framework Programming Guide]. The most elegant way to do this is in the Deployment section of the Build settings.

As you work on your framework, there are times when you do want to update the framework when you do a build, and times when you don't. For that reason, I change the Deployment settings only in the Release Configuration. So:

  1. Double-click on the framework target to bring up the Target info window and switch to the Build tab.
  2. Select Release in the Configuration selectbox.
  3. Scroll down to the Deployment section and enter the following values:

Deployment Location = YES (click the checkbox)

Installation Build Products Location = /

Installation Directory = /Library/Frameworks

The Installation Build Products Location serves as the root of the installation. Its default value is some /tmp directory: if you don't change it to the system root, you'll never see your installed framework since it's hiding in the /tmp.

Now you can work on your framework as you like in the Debug configuration without upsetting your other projects and when you are ready to publish all you need to do is switch to Release and do a Build.

Xcode 4 Warning Since switching to Xcode 4, I've experienced a number of problems with my custom framework. Mostly, they are linking warnings in GDB that do not really interfere with the usefulness of the framework, except when running the built-in unit-test. I have submitted a technical support ticket to Apple a week ago, and they are still looking into it. When I get a working solution I will update this answer since the question has proven quite popular (1 kViews and counting).

like image 64
Elise van Looij Avatar answered Sep 29 '22 10:09

Elise van Looij