我对使用 Cocoa 的 Objective-C 还很陌生,我需要帮助。
我有一个 for 语句,其中我将 i 从 1 循环到 18,我想在此循环中向 NSMutableArray 添加一个对象。现在我有:
chapterList = [[NSMutableArray alloc] initWithCapacity:18];
for (int i = 1; i<19; i++)
{
[chapterList addObject:@"Chapter"+ i];
}
我希望它添加对象,第 1 章、第 2 章、第 3 章...、第 18 章。我不知道该怎么做,或者即使可能。有没有更好的办法?请帮忙
提前致谢
最佳答案
chapterList = [[NSMutableArray alloc] initWithCapacity:18];
for (int i = 1; i<19; i++)
{
[chapterList addObject:[NSString stringWithFormat:@"Chapter %d",i]];
}
祝你好运
关于objective-c - 将一个字符串后跟一个 int 添加到数组中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5373728/