我们不再需要将框架链接到XCode项目吗? [英] Don't we need to link framework to XCode project anymore?

查看:65
本文介绍了我们不再需要将框架链接到XCode项目吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基于此问题

为什么不需要将iOS框架依赖项显式链接到静态库

我阅读了所选答案,但仍然不理解,因此我制作了一个示例项目

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

在Github上测试项目

在测试项目中,我从主项目和静态库(包括Foundation.framework和UIKit)的使用库链接二进制文件文件导航中删除了所有框架.框架),基本上,两个项目都链接到0个框架.

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.

问题是

  • 在静态库中,它包含MapKit/MapKit.h,而没有将Mapkit.framework引用到项目中,为什么它仍然起作用?
  • 在主项目中,我从项目中删除了UIKit.framework和Foundation.framework,为什么它仍然起作用?
  • 因为它现在正在工作,以后还会有问题吗?

谢谢您的评论.

P.S.通过工作,我的意思是我可以在模拟器上运行,并且可以将主项目归档而没有任何错误.

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

编辑2014年7月25日

我尝试过使用的真实应用程序是一样的.

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

  • 我重点介绍了File Navigation中的Foundation,UIKit,CoreData和另外10个框架.
  • 在实用工具面板中取消选中目标->目标成员身份
  • 构建:通过,运行:通过

我的应用程序的所有功能仍按预期运行.我不明白.

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

推荐答案

检查项目的构建设置.在 LLVM 5.1 —语言—模块下,您应该看到自动链接框架"选项.就您而言,这听起来像是默认设置为是".

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.

在这种情况下,当您引用编译器不知道的类时,它不会产生错误,而是会找出哪个Framework包含该类并进行链接.在您的代码中,它将是MKMapView或触发链接的其他MapKit类之一.

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.

来自相关的新功能?"文档:

为代码模块导入的框架启用了自动链接.什么时候 源文件包括来自支持以下内容的框架的标头 模块,编译器会在目标文件中生成额外的信息 自动链接到该框架.结果是,在大多数情况下 情况下,您无需指定框架的单独列表 在使用支持以下内容的框架API时与目标链接 模块.

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.

另一种看待它的方法是,当适当构建框架时,编译器足够聪明,可以将#import更改为@import.所有系统框架都已完成.

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.

这篇关于我们不再需要将框架链接到XCode项目吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆