Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When do you have to link Frameworks and Libraries to an XCode project?

Tags:

Background: I started a test Swift project to understand and expand my knowledge on how to implement CoreData into my projects. And of course whenever I'm just testing and playing around with code, I always get sidetracked and seem to get stuck on some tangential topic. This one now being when is it necessary that you directly link a Framework or Library to an XCode project.

So how this came up... I'm creating subclasses of NSManagedObject for which I have to (write) import CoreData in my Swift file. And everything seems to be working perfect; no errors, warnings, etc. However when I check which frameworks and libraries are linked to my project in my "project and targets listing" none are listed. I then realize same goes for when you have to import UIKit. Obviously there's the option to directly link these frameworks but it doesn't seem it is necessary to do so.

So as for my question, are there default frameworks that don't have to be explicitly linked to XCode projects, or will I have to eventually link these frameworks when I package up my project for deployment? And if this is not the case, from a broader standpoint, when is it necessary to explicitly link Frameworks and Libraries to an XCode project?

Edit***

If all Apple frameworks are already automatically linked.... Then what is the point of having them available to add to your project. (Mind you, CoreData.framework wasn't originally linked explicitly like it is in the picture.)

Project Settings

like image 556
Yonny Avatar asked Nov 16 '15 04:11

Yonny


People also ask

Where is linked frameworks and Libraries in Xcode?

If you're building for iOS, tvOS, or watchOS: On your application targets' “General” settings tab, in the “Linked Frameworks and Libraries” section, drag and drop each framework you want to use from the Carthage/Build folder on disk.

How do I add a framework to a project 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.

What are Xcode frameworks?

A framework is a hierarchical directory that encapsulates shared resources, such as a dynamic shared library, nib files, image files, localized strings, header files, and reference documentation in a single package. Multiple applications can use all of these resources simultaneously.

What is framework target in Xcode?

A framework target means that your project compiles your code into a library which can then be consumed by other programs. CocoaPods are examples of frameworks. Unless you are building your own frameworks, you should pick "App Target".


1 Answers

There is no magic happening.

This is because of module and auto-linking introduced by Xcode(LLVM).
(related keywords : @import rather than #import and build-setting options like Enable Modules, Link frameworks automatically, by default, set to YES both). enter image description here

Automatically, these two keyword(module, auto-linking flag options) combinations try to find and add any related all frameworks that support modules.

As introduced from Xcode 5(actually, LLVM and clang compiler front-end), Internally, the LLVM with above default projects setting has been to use the module system to automatically link any frameworks in code through @import/#import statements.

Once the frameworks are automatically linked with that, developers don't need to put them in Linked Frameworks & Libraries anymore.

So, That's why Apple system frameworks(default frameworks) do not have to be explicitly linked to Xcode projects.

Since the module was available in Xcode, there is no need to continue to import all system frameworks list in .pch file(precompiled prefix header.) So, that's why also pch setup is set to NO and no needed by default behind the scene.

The limitation, as far as I know so far, is these are only available for Apple system frameworks until now, meaning it cannot be applied to user frameworks and other C/C++ libraries.

Hope it helps.

like image 167
boraseoksoon Avatar answered Sep 27 '22 19:09

boraseoksoon