-2

Possible Duplicate:
Property Declaration and Automatic Backing Storage Allocation

I know the basic functions of @property and @synthesize directives, but recently I found a sample code: enter image description here

There's not any class member variables in TTDownloader, but it works perfect.

TTDownloader *dl = [[TTDownloader alloc] init];
NSLog(@"%d %@", dl.aaa, dl.bbb); // result: 0 (null)
dl.aaa = 101;
dl.bbb = [NSNumber numberWithInt:201];
NSLog(@"%d %@", dl.aaa, dl.bbb); // result: 101 201

My questions are listed below:

  1. Where is aaa and bbb? I don't even have a place to hold these data. TTDownloader is empty (except some variables and functions derived from NSObject).

  2. Did I miss some great features of Objective C? Are they described in Obj-C Programming Guide, I just read part of it.

Thanks in advance.

Community
  • 1
  • 1
Tony
  • 158
  • 10
  • 3
    possible duplicate of [Property Declaration and Automatic Backing Storage Allocation](http://stackoverflow.com/questions/3238009/) and [Must every ivar really be property](http://stackoverflow.com/questions/5031230/) and [What's the purpose of an ivar when a property exists](http://stackoverflow.com/questions/3336922/) and [Why don't I need an ivar for this property](http://stackoverflow.com/questions/6837584) and [What is the difference between ivar and property](http://stackoverflow.com/questions/4299487/) and [Defining ivar and property](http://stackoverflow.com/questions/7854901/) – jscs Oct 26 '11 at 07:50

1 Answers1

1

In the modern runtime on all platforms except 32 bit OS X, when you synthesize a property, if the instance variable has not been declared, it will be created automatically. so

  1. aaa and bbb are properties i.e. each is a pair of accessor methods which are synthesized and use the instance variables _aaa and _bbb respectively.

  2. Yes, see above.

JeremyP
  • 84,577
  • 15
  • 123
  • 161