开发者

xcode: NSArray slice method?

开发者 https://www.devze.com 2023-02-27 01:22 出处:网络
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\"

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)

0

精彩评论

暂无评论...
验证码 换一张
取 消