开发者

Insert 12 objects into NSMutableArray

开发者 https://www.devze.com 2023-02-20 10:57 出处:网络
I wish to add 12 objects to a nsmutablearray, ready for the command InsertObject:atIndex: There must be a quicker way than

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

精彩评论

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