条件编译支票框架在导入前 [英] Conditional compilation check for framework before importing

查看:198
本文介绍了条件编译支票框架在导入前的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在寻找一种方法来检查,如果它的类定义,进口和使用的框架之前的框架存在,和/或。具体来说,框架是资产库。


I'm looking for a way to check if a framework exists and/or if it's classes are defined, before importing and using that framework. Specifically, the framework is Assets Library.

目前,我能够与核心数据框架,要做到这一点,因为该框架有一个名为CoreDataDefines.h文件,它提供了一个preprocessor指令_COREDATADEFINES_H。这让我简单地检查了确定指标,像这样:

Currently, I'm able to do this with the Core Data framework, since that framework has a file called CoreDataDefines.h which provides a preprocessor directive _COREDATADEFINES_H. This allows me to simply check for that defintion like so:

#ifdef _COREDATADEFINES_H
#import <CoreData/CoreData.h>

// do something with Core Data

#else

// do something without using Core Data

#endif


不幸的是,资产库并没有提供一个明确的定义头文件,所以我在寻找一种方式来写我自己的#define语句,可以导入前检查框架的存在,就像我有以上核心数据完成的。


Unfortunately, the Assets Library does not provide a clear definitions header file so I'm looking for a way to write my own #define statement that can check for the framework's existence before importing it, much like I have done for Core Data above.

我已经试过这样:

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 40000
// import assets library if defined !
#define ASSETSLIBRARY_DEFINE    (NSClassFromString(@"ALAsset") != nil)
#if ASSETSLIBRARY_DEFINE
#import <AssetsLibrary/AssetsLibrary.h>
#endif
#endif

...但没有运气。

编译器告诉我,令牌不在preprocessor ​​SUBEX pression有效的二元运算符。

... but no luck.
The compiler tells me that the "Token is not a valid binary operator in a preprocessor subexpression."


任何帮助始终是多少AP preciated。


Any help is always much appreciated.

推荐答案

如果你知道你可以查阅一下类应与框架导入,如果它被加载:

If you know what class should be imported with the framework you can check if it is loaded:

BOOL isFrameworkLoaded = (NSClassFromString(@"MyClassNameFromTheFramework") != nil);

这篇关于条件编译支票框架在导入前的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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