November 2013
Beginner
325 pages
9h 47m
English
Most beginning programmers are surprised by the immutability of NSArray, NSSet, and NSDictionary. Why would anyone want a list that cannot be changed? The reasons are performance and security:
You do not trust the people you work with. That is, you want to let them look at an array, but you do not want them to be able change it. A gentler approach is to give them an NSMutableArray but tell them it is an NSArray. For example, consider the following method:
// Returns an array of 30 odd numbers
- (NSArray *)odds
{
NSMutableArray *oddsArray = [[NSMutableArray alloc] init];
int i = 1;
while ([oddsArray count] < 30) {
[oddsArray addObject:[NSNumber numberWithInt:i];
i += 2;
}
return oddsArray;
}
Anyone calling this ...
Read now
Unlock full access