0

I'm kind of confused about something. So I understand the memory management portion of doing something like

self.someProp = someObject;

But when you declare something as

@synthesize someProp = _someProp;

and you try to access _someProp in a subclass of the object, I get an error sayint that _someProp has not been declared. But if I do self.someProp I dont' get the error. Can someone explain what the differences are in these scenarios? Thanks.

J W
  • 868
  • 1
  • 12
  • 25

2 Answers2

3

It basically creates the following code:

@implementation myClass
{
    @private
    id _someProp; // notice it's a private implementation property
}

-(id) someProp
{
    return _someProp;
}

-(void) setSomeProp:(id) prop
{
   [_someProp release];
   _someProp = [prop retain];
}

@end

The private implementation property means that it cannot be accessed outside of the class, and isn't a part of the interface, but a part of the implementation.

Richard J. Ross III
  • 55,009
  • 24
  • 135
  • 201
1

@synthesize someProp = _someProp; creates getter and setter methods in your class. The methods are named someProp and setSomeProp. These method get and set a private variable named _someProp which is why that name is not available to your subclasses.

picciano
  • 22,341
  • 9
  • 69
  • 82