6

I'm writing a library of reusable code intended for both OS X and iOS. I created an Xcode project with 2 targets. One target is a framework for OS X. The other is a static library for iOS.

I discovered that builds of the OS X framework target are trying to use the iOS headers. I know this because TARGET_OS_IPHONE is defined causing the build to attempt to find UIKit.h, etc. This of course causes builds for the framework target to fail since the OS X framework target does not link to iOS frameworks.

I checked the build settings for the OS X framework target for goofiness but found nothing. The base SDK is set as "Mac OS X 10.6". Note when I created the Xcode project, I used the Cocoa Framework template then later added the iOS static library target.

What else could cause the OS X framework target to use the wrong SDK?

Thanks, -KIRBY

4
  • On a related note, I also found switching between the active targets causes the framework target to change its type, displayed on the General tab for the target, from "framework" to "com.apple.product-type.framework". I'm starting to think the problems might be a bug in Xcode and filing a radar is more appropriate than this SO posting. Commented Jan 28, 2011 at 12:54
  • More of the mystery solved. TargetConditionals.h in Mac10.5.sdk does not define TARGET_OS_IPHONE. Mac10.6.sdk does define it as 0. Code using #ifdef TARGET_OS_IPHONE will not work as expected when compiled against Mac10.6.sdk. Need to use #if instead. Apple uses #if in the sample listings in the "Compiling Source Code Conditionally for iOS Applications" section of the iOS docs. Commented Jan 29, 2011 at 4:02
  • As an aside, it is possible to create iOS frameworks, but not with Xcode. They behave a little differently. See accu.org/index.php/journals/1594 Commented Feb 16, 2011 at 8:25
  • You can also do this in Xcode - even static-lib based frameworks. see my answer below. Commented Jan 7, 2016 at 17:38

3 Answers 3

1

Your issue is that Xcode's gotten confused. Option click on the Overview popup and reset your Active SDK to Base SDK. You'll probably find that the Mac target is set to one of the iOS targets, which ends up causing all sorts of hilarity as you've seen

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Mike. Your suggestion fixes half the problem. Reseting the Active SDK fixes the weirdness of the Get Info > General tab type showing "com.apple.product-type.framework" instead of Framework. It also changes the target icon back from the bullseye to the toolbox. But it doesn't fix the build issues. It still wants to use the iOS headers.
0

I've had some goofy issues putting both a Mac and iPhone target in the same Xcode project file, much like what you describe in your question and accompanying comment. My solution is to have a separate Xcode project file for Mac and iOS. You can still share files between the projects, although you have to keep each one individually updated, but it results in less glitchy behavior.

1 Comment

Separate projects is mine current workaround too, but it's not an idea solution. I can recreate the issue in new projects, which means it's radar time. Thanks for the reply.
0

I am doing something very similar to what you describe. I have several private frameworks that are shared between our iOS app and our OS-X app. Each such framework resides in its own project, with two targets. A Mac-OS dynamic frameworks, and a special iOS "static framework" using a special template we added to Xcode - it's an open source project Karl Stenerud's iOS universal iOS framework Now I never experienced the goofiness you describe, and I'm sure it's just something you mistakenly deleted (or added) in the project/target settings.

What I'll recommend as a "debugging method" for the project settings is this.

Have a nice text editor open for you. Go to the build-settings of the iOS static lib for instance. Choose the "All" and "Combined" buttons. Now select all the lines and Copy (command-C). Go to the text editor, and paste. You'll have a nice text description of all the settings.

Now create a new template project in Xcode, and do the same into another text file. Now compare these files, for discrepancies.

Do this on all 3 levels. 1. Project level settings 2. iOS static lib settings 3. OS-C framework.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.