私が見ている機能:
-(void)viewDidLoad {
NSBundle *bundle = [NSBundle mainBundle];
NSString *plistPath = [bundle pathForResource:@"statedictionary" ofType:@"plist"];
NSDictionary *dictionary = [[NSDictionary alloc] initWithContentsOfFile:plistPath];
self.statesZips = dictionary;
[dictionary release];
NSArray *components = [self.stateZips allKeys];
NSArray *sorted = [components sortedArrayUsingSelector:@selector(compare:)];
self.States = sorted;
NSString *selectedState = [self.states objectAtIndex:0];
NSArray *array = [stateZips objectForKey: selectedState];
self.zips = array;
}
NSDictionary が割り当てられ、次に *dictionary というポインターに割り当てられ、次にインスタンス変数 stateZips に割り当てられるのはなぜですか? それを割り当ててインスタンス変数に直接割り当て、別の NSDictionary の作成と解放のメモリを節約してみませんか? NSArray を使用したこの関数の後半を含め、常に同じ方法論に従います...
NSDictionary *dictionary = [[NSDictionary alloc] initWithContentsOfFile:plistPath];
self.statesZips = dictionary;
[dictionary release];
また、このソートでは、ハッシュ テーブル (辞書) のキーがアルファベット順に並べられます。この行を理解しているかどうかわかりません:
NSArray *sorted = [components sortedArrayUsingSelector:@selector(compare:)];