Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Don't we need to link framework to XCode project anymore?

Tags:

xcode

ios

Base on this question

Why don't iOS framework dependencies need to be explicitly linked to a static library

I read the selected answer and still don't understand so I made an example project

Test Project on Github

In the test project, I remove all framework from Link Binary With Libraries and File navigation for both main project and the static library (including Foundation.framework and UIKit.framework too), basically, both project link to 0 frameworks.

Questions are

  • In static library, it's including MapKit/MapKit.h without referencing the Mapkit.framework to the project, why is its still working?
  • In main project, I remove UIKit.framework and Foundation.framework from the project, why is it still working?
  • Since it's working for now, will there be any issue later?

Thank you for your comment.

P.S. By working, I mean I can run on the simulator and I can archive the main project without any error.

Edit 25/07/2014

I tried with the real app that I'm working on, it's the same.

  • I highlight Foundation, UIKit, CoreData and 10 another frameworks in File Navigation, well, all of them.
  • Uncheck the target in Utilities Panel --> Target Membership
  • Build : Pass, Run : Pass

Every functionality of my app is still working as expected. I don't get this.

like image 647
Tar_Tw45 Avatar asked Jul 23 '14 05:07

Tar_Tw45


People also ask

How do I link a framework in Xcode?

To include a framework in your Xcode project, choose Project > Add to Project and select the framework directory. Alternatively, you can control-click your project group and choose Add Files > Existing Frameworks from the contextual menu.

Why are frameworks red in Xcode?

The red text indicates that the actual files are not at the path that the project has for them. Get info on the framework and look under the General tab. The first section shows the name and path of the framework bundle itself.

How do I add a framework to a swift project?

In the app, select the project from the project navigator, select the Stocktance target, and scroll to Frameworks, Libraries, and Embedded Content. Click on the plus button, click Add Other… and select Add Files… Navigate to the SettingsKit folder and select it. We've added the framework to the project.


1 Answers

Check your project build settings. Underneath LLVM 5.1 — Language — Modules you should see the option 'Link Frameworks Automatically'. In your case it sounds like it's set to 'YES', the default.

In that case, instead of producing an error when you reference a class that the compiler doesn't know, it'll figure out which Framework contains that class and link it. In your code it'll be MKMapView or one of the other MapKit classes that triggers the linkage.

EDIT: from the relevant 'What's New?' document:

Auto Linking is enabled for frameworks imported by code modules. When a source file includes a header from a framework that supports modules, the compiler generates extra information in the object file to automatically link in that framework. The result is that, in most cases, you will not need to specify a separate list of the frameworks to link with your target when you use a framework API that supports modules.

Another way of looking at it is that the compiler is smart enough to mutate #import to @import when the framework has been built appropriately. All system frameworks have been.

like image 144
Tommy Avatar answered Sep 24 '22 06:09

Tommy