ambientlight ambientlight - 1 year ago 126
iOS Question

Xcode: Universal framework: Conditionally link other .framework dependency for specific platform only

While working with universal framework that targets all apple platforms I wish to conditionally link to another

dependency for OSX only.

I can add this dependency to Linked Framework and Libraries and mark it as Optional. However I don't know what custom field should I add or modify in
Build Settings
to only actually link this
for specific platform only. (without anything since the dependency is optional - build will always fail with
ld: framework not found

Any suggestion guys?

As a workaround I can split this over two targets: one for OSX and one for anything else, but that will already derail the concept of universal framework.

Answer Source

This can be achieved without resorting to Linked Framework and Libraries.

While we have a universal target with full range of supported platforms: macosx iphoneos iphonesimulator appletvos appletvsimulator watchos watchsimulator, consider the case that we want to link a framework for OSX only.

For linking our framework we need two things:

  1. Add the path to desired .framework to Framework Search Path
  2. Add -framework YourFrameworkName to Other Linker Flags

And Build settings allows us to specify fields conditional for specific platform. When expanding the individual field and hovering the mouse over Debug/Release, you will be able see the plus sign appearing, pressing on the plus sign will bring you the picker where you will be able to select the desired platform.

The hypothetical added build settings for linking Realm and RealmSwift for OSX will look the following way:

(both Intel 64-bit arch and Any macOS SDK will represent building for OSX)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download