disabling ARC for .h files iphonesdk

心已入冬 提交于 2019-12-11 03:50:37

问题


My projects uses ARC and I want to use GDATA api which is not ARC Compatible. I know how to disable ARC for single file(by adding the -fno-objc-arc compiler flag for those files). But in GDataObject.h file there is a structure defenition as

typedef struct GDataDescriptionRecord {
    NSString *label;
    NSString *keyPath;
    enum GDataDescRecTypes reportType;
} GDataDescriptionRecord;

It causes an error like

ARC forbids object in struct or union

How can I avoid this problem. Is there any ARC compatible GDATA api available or any way to disable arc for .h files


回答1:


I would use something like this:

#if __has_feature(objc_arc)
#define ARC_MEMBER __unsafe_unretained
#else
#define ARC_MEMBER 
#endif

Then, your structure would look something like this:

typedef struct GDataDescriptionRecord {
    ARC_MEMBER NSString *label;
    ARC_MEMBER NSString *keyPath;
    enum GDataDescRecTypes reportType;
} GDataDescriptionRecord;


来源:https://stackoverflow.com/questions/9895144/disabling-arc-for-h-files-iphonesdk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!