我想了解哪个函数是正确的,希望有人能在 func1 和 func2 之间给我建议。
现在我用func1,有人告诉我func2有内存问题。
@property (nonatomic) NSDictionary *NameAndIdDictionary;
- (void) func1
{
__weak NSDictionary *NameAndIdDictionary = self.NameAndIdDictionary;
self.Keys = [[NameAndIdDictionary allKeys] sortedArrayUsingComparator: ^NSComparisonResult(id obj1, id obj2) {
NSString *name1 = (NSString *)NameAndIdDictionary[obj1];
NSString *name2 = (NSString *)NameAndIdDictionary[obj2];
return [[name1 uppercaseString] compare:[name2 uppercaseString]];
}];
}
- (void) func2
{
self.Keys = [[self.NameAndIdDictionary allKeys] sortedArrayUsingComparator: ^NSComparisonResult(id obj1, id obj2) {
NSString *name1 = (NSString *)self.NameAndIdDictionary[obj1];
NSString *name2 = (NSString *)self.NameAndIdDictionary[obj2];
return [[name1 uppercaseString] compare:[name2 uppercaseString]];
}];
}