Im just about to refactor my current iOS project to use ARC. And after previewing the changes to migrate my current code to ARC using the "Refactor to ARC" tool i xCode, i can see my current code conventions probably not suited for ARC. Because it adds alot of __weak / __strong etc to my ivars.
Heres how my current conventions are:
i define all instance variables as private or protected ivars. and all public variables i create a @property for.
@interface TestClass
{
@private
NSMutableArray* mArray;
NSString* mString;
BOOL mMyBoolean;
}
@property (retain, nonatomic) NSString* string; // public
@end
All objects i always back with a @property, to avoid dealing with release / retain so if i have a private variable that is a reference, i just create a category in the implementation. Struct (like mMyBoolean) i just leave define as a ivar.
@interface TestClass()
@property (retain, nonatomic) NSmutableArray* mArray;
@end
@implementation TestClass
@synthesize string = mString;
@synthesize mArray;
@end;
But because the new ARC is taking care of retain / release i properly dont need private variables to be backed by @property.
So what code conventions would be more appropriate? Ive been thinking about just defining properties in the interface like this:
@interface TestClass
{
@private
NSMutableArray* mArray;
BOOL myBoolean;
}
@property (strong, nonatomic) NSString* string;
@end
@implementation TestClass
@synthesize string;
@end
And dont use category properties for private properties. (also i removed the "m" prefix) and i dont define the backed ivar that @property should use, instead i just let xcode use its autogenerated?.