0
在這個簡單的測試中,在確定索引有效之後,是否值得分配一個變量而不是調用兩次objectAtIndex:method?在Cocoa中優化測試
NSString *s = [myArray objectAtIndex:2];
if (s) {
Test *t = [Test initFromString:s];
}
代替
if ([myArray objectAtIndex:2]) {
Test *t = [Test initFromString:[myArray objectAtIndex:2]];
}