xcode: NSArray slice method?
How can I create a NSSet or NSArray X with first 5 element开发者_如何学JAVAs of NSArray or NSSet Y?
NSArray *X = [NSArray arrayWithObjects:@"foo", @"bar", @"test", @"blah", @"yeah", @"lost", nil];
NSArray *Y = [X subarrayWithRange:NSMakeRange(0,5)];
The resulting array Y will contain the first five elements of the first array X.
NSMutableArray x = [[NSMutableArray alloc] init];
for (int i=0; i<5; i++)
{
[x addObject:[y objectAtIndex:i]];
}
(y is the other NSMutableArray)
精彩评论