Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

BID IOS 7: Chapter 9, Page 286

I'm confused regarding the following code and was hoping someone can help to clarify:

-(NSArray *)pointSizes
{
static NSArray *pointSizes = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
pointSizes = @[@9,
@10, @11, ...@144];
});
return pointSizes;
}

Further in the code, inside the "cellForRowAtIndexPath" data source method, the array returned by the above is later accessed as if it were a property, like this:

self.pointSizes[indexPath.row];

But how is that so?  Wouldn't you first have to invoke the method and store the output into a variable before accessing it in this manner?  I know that you can access class properties using dot referencing, but this appears to be accessing the static variable inside the function since it is passing the index to the array object of the item in question.  And without explicitly invoking the method first, how would the static variable ever be initialized in the first place?

It's probably some subtle thing that I'm missing here, but I could use some clarity if anyone can provide it.

Thanks!
Sign In or Register to comment.