Xcode和可选框架 [英] Xcode and optional frameworks

查看:81
本文介绍了Xcode和可选框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

链接的框架和库下,有一个必需可选选项.

Under Linked frameworks and libraries there is a Required or Optional option.

有人可以解释一种情况以及如何使用可选框架吗?假设我可以看到这样的情况:我有一些测试数据并包含了 IF 框架,我想启用某种功能,如果不包括在内,也许我什么都不做. ..

Could somebody explain a situation in which and how to work with an optional framework? I could see hypothetically a situation where I have some test data and IF the framework is included I would want to enable some sort of functionality and if it is not included than perhaps I wouldn't do something....

但是,否则,您什么时候想要使用可选框架我就茫然了

But otherwise I'm at a loss as to when you would want to use an optional framework

(如果存在,那么一个代码示例会很棒)

(a code example would be awesome if one exists)

推荐答案

如果您针对的是某些框架可能尚不可用的旧OS版本,则可选链接很有用.在这种情况下,您可以将给定框架的链接设置为可选,如果

Optional linking is useful if you're targeting older OS versions where a certain framework might not be available yet. In this case you can set the linkage of the given framework to optional, and this causes the program not to crash on launch if dlopen cannot find the given framework.

然后在您的代码中,可以在该框架的用法周围放置警卫声明,以避免因使用未解析的符号而使b/c崩溃:

Then in your code you can put guard statements around the usage of this framework in order to avoid crashing b/c of using unresolved symbols:

 if (MyWeakLinkedFunction != NULL)
 {
     result = MyWeakLinkedFunction(); // this function comes from a weakly/optionally linked framework
 }

请参阅:框架和弱链接

这篇关于Xcode和可选框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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