Search code examples
iphoneautomatic-ref-countinggdata-api

disabling ARC for .h files iphonesdk


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


Solution

  • 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;