This morning, I ran into a crash in the iPhone app I’m working on, and while I fixed the error, I'm curious why the syntax reason was a problem.
Here is my code reduced to simple elements. I populate items in a TableView using NSArray for items. NSArray is a property:
@interface FooViewController : UITableViewController { NSArray *stuff; } @property (nonatomic, retain) NSArray *stuff;
And in my implementation file:
@synthesize stuff; - (void)viewDidLoad { NSArray *arr = [[NSArray alloc] initWithObjects:@"", @"Item 1", @"Item 2", @"Lorem", @"Ipsum", nil]; self.stuff = arr; [arr release]; }
Now, when I first wrote the method, I accidentally left the "I". and it caused a bomb. Although during testing it worked first to blush. I tried:
stuff = arr; NSLog(@"%d", [stuff count]);
But using material in other methods of bombardment. Now that I have fixed the problem, I can use [number of pieces] in other places.
So why can I use material in some places, but in others should I use self.stuff ?
Dana
source share