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

后端 未结 2 1802
挽巷
挽巷 2021-02-02 17:35

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 understa

相关标签:
2条回答
  • 2021-02-02 17:57

    To elaborate @Tommy's answer, a framework that supports modules satisfies the following 2 conditions:

    Under Build Settings > Packaging

    • Define Modules is set to YES
    • Module Map File exists.

    So, if you're certain that the framework you're using in your code modularizes like that, you can choose to not explicitly add it in the link phase as it will be automatically added as long as in the project file, under Apple Clang - Language - Modules, The option Link Frameworks Automatically is set to YES.

    0 讨论(0)
  • 2021-02-02 18:02

    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.

    0 讨论(0)
提交回复
热议问题