How to convert Non ARC to ARC project while project having C-Structures?
automatic-ref-counting, ios6, objective-c
Solution
You have substantially two options here:
Add the `-fno-objc-arc` flag to the files you don't wanna convert to ARC, but of course you cannot convert them otherwise it would not compile, in the best case, and tremendously leak in the worst one.
Convert all the classes and solve the issue with the Objective-C objects inside C structs.
Concerning the second solution you have again a couple of options:
Replace C structs with full-fledged objects and let ARC handle memory for you
Keep using C structs and mark the objects part of them as `__unsafe_unretained` which basically will tell ARC to disregard those objects for the memory management. Therefore you will have something like:
typedef struct {
NSInteger anInteger;
__unsafe_unretained NSString * aString;
} AStruct;
This will compile under ARC and it's the only option you have for keeping Objective-C objects inside a C struct. Please keep in mind that ARC won't manage the memory for those objects, so you have take care of it manually.
Bottom line, my advice is to convert your C structs into classes. As an example, you can easily convert the above struct into:
@interface AStructReplacement : NSObject
@property (nonatomic, assign) NSInteger anInteger;
@property (nonatomic, strong) NSString * aString;
@end
which is much safer, more coherent and easier to use than a C struct.
Problem
I have an Xcode 4.5.1 . I want to convert this project to ARC to improve the performance.I am following these steps. Edit->Refactor->Convert to Objective C ARC but getting error: ARC forbids Objective-C objects in structs or unions. - I know, i can prevent these classes to converting to ARC by adding -fno-objc-arc to the compiler options. but i want to convert these classes also to ARC. Is it possible? - How to allow that xcode should check only some classes for ARC conversion? For example when i am converting to arc it checks the classes code, but i have some classes those are not to convert to arc. so want that Xcode should not generate error for them within conversion process. is it possible?