What is the proper way to work with instance variables (declared on interface), their @property
and @synthesize
, when working in ARC project? What I now do is following:
SomeClass.h:
@interface SomeClass : NSObject {
NSString *someString;
}
@property(nonatomic, copy) NSString* someString;
and SomeClass.m:
@implementation SomeClass
@synthesize someString;
- (void)someMethod {
self.someString = @"Foobar";
}
The thing is that there are other approaches that works, like using just the @property:
SomeClass.h:
@interface SomeClass : NSObject
@property(nonatomic, copy) NSString* someString;
Accessing the someString
without self
:
SomeClass.m:
@implementation SomeClass
@synthesize someString;
- (void)someMethod {
someString = @"Foobar";
}
etc. I'm new to Objective-c, I'm used to Java. What is the proper way to work with attributes then? I understand that special cases will have special behavior, but what is the best approach in general? (by general I mean I want to access the variable from the class itself and from "outside" and I want ARC to still work correctly, eg. I don't have to worry about memory leaks)
@synthesize
statement was actually introduced with Xcode 4.4. – Refined