small medium large xlarge

26 May 2010, 10:11
Tony Daly (1 post)

I thought I understood the use of @self@. When we use the @@property@ to create the getters and setters, we use @self@ to go through those, so we get all the memory benefits etc. However, in Chapter 16 ‘Displaying Data in a Table’, section 16.5 ‘Solution: Introducing a Data Source’ there seems to be some inconsistencies in the usage.


- (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView { 
    return [runningApps count];

This accesses the @runningApps@ instance directly. But in the following:

- (id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)nibBundle { 
    if (self = [super initWithNibName:nibName bundle:nibBundle] ) {
        self.runningApps = [NSMutableArray arrayWithCapacity:20]; 
        [self.runningApps addObjectsFromArray:[[NSWorkspace sharedWorkspace] runningApplications]];
    return self;

Uses @self@. Is there any reason for this difference? Or have I misunderstood the use of @self@?

You must be logged in to comment