开发者

Insert 12 objects into NSMutableArray

I wish to add 12 objects to a nsmutablearray, ready for the command InsertObject:atIndex:

There must be a quicker way than

    [self.YoutubeArray addObject:@""];
    [self.YoutubeArray addObject:@""开发者_运维知识库];
    [self.YoutubeArray addObject:@""];
    [self.YoutubeArray addObject:@""];
    [self.YoutubeArray addObject:@""];
    [self.YoutubeArray addObject:@""];
    [self.YoutubeArray addObject:@""];
    [self.YoutubeArray addObject:@""];
    [self.YoutubeArray addObject:@""];
    [self.YoutubeArray addObject:@""];
    [self.YoutubeArray addObject:@""];
    [self.YoutubeArray addObject:@""];


for (NSInteger i = 0; i < 12; i++) {
    [self.YoutubeArray addObject:@""];
}


self.YoutubeArray = [NSMutableArray arrayWithObjects:@"",@"",...,@"",nil];

if you use static data


I'm guessing you don't actually NEED those empty strings, you're just setting up placeholders?

If so:

self.YoutubeArray = [NSMutableArray arrayWithCapacity:12];

Otherwise:

self.YoutubeArray = [NSMutableArray arrayWithObjects:@"", @"", @"", @"", @"",
                     @"", @"", @"", @"", @"", @"", @"", nil];


NSMutableArray *arr = [NSMutableArray arrayWithObjects:@"" count:12];
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜