15

If I declare a property like this:

@property(nonatomic,weak) Foo *someProperty;

and I then declare a custom setter like so:

- (void)setSomeProperty:(Foo *)someProp {
    _someProperty = someProp;
    //...more custom stuff
}

is there anything wrong with this? That is, the compiler should automatically synthesize the _someProperty ivar with the __weak modifier, so just doing the assignment in the setter above should suffice, correct?

adevine
  • 1,074
  • 9
  • 23

1 Answers1

12

Yes, that's all there is to it. Of course you can specify a custom iVar if you'd like something other than _someProperty like:

@synthesize someProperty = someProperty_;
Richard Brown
  • 11,346
  • 4
  • 32
  • 43
  • Thanks very much! So, as I understand it, if you are writing a custom setter in ARC, the only time you need to worry about "overriding" the attributes on the property declaration is if you have the property declared with atomic (in which case you would need to @synchronize around setting the iVar) and copy (in which case your assignment statement would look like _someProperty = [someProp copy]; ) – adevine Mar 25 '13 at 14:13