6
Đây có phải là cách đúng và hiệu quả nhất để xóa chuỗi trống khỏi NSArray không?Đây có phải là cách đúng và hiệu quả nhất để xóa chuỗi trống khỏi NSArray không?
int main(int argc, char *argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSMutableArray *myStrings = [NSMutableArray arrayWithObjects:(id[]){@"Test 1",@"",@"Test 2",@"Test 3",@""} count:5];
NSArray *myFilteredArray = [myStrings filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"length > 0"]]; //Non-destructive, myStrings is still intact
NSLog(@"The original array is: %@",myStrings);
NSLog(@"The filtered array is: %@",myFilteredArray);
[myStrings removeObject:@""]; //Destructive. myStrings will never be the same again
NSLog(@"The altered is: %@",myStrings);
[pool drain];
return 0;
}
Cảm ơn Daniel .. Tôi nghĩ bạn đã hoàn toàn đúng .. !! Câu trả lời chính xác..!! –