gpt4 book ai didi

iphone - 如何使用 for 循环将对象添加到 NSArray?

转载 作者:IT王子 更新时间:2023-10-29 08:01:53 24 4
gpt4 key购买 nike

我想使用 for 循环将 [NSDecimalNumber numberWithInt:i] 添加到数组中。

它是硬编码的:

 NSArray *customTickLocations = [NSArray arrayWithObjects: [NSDecimalNumber numberWithInt:1],[NSDecimalNumber numberWithInt:2],[NSDecimalNumber numberWithInt:3],[NSDecimalNumber numberWithInt:4],[NSDecimalNumber numberWithInt:5],[NSDecimalNumber numberWithInt:6],[NSDecimalNumber numberWithInt:7],[NSDecimalNumber numberWithInt:8],[NSDecimalNumber numberWithInt:9],[NSDecimalNumber numberWithInt:10],[NSDecimalNumber numberWithInt:11],[NSDecimalNumber numberWithInt:12],nil];

我想要这样,但我只能在这里添加一个对象....

for (int i=0; i<totalImagesOnXaxis; i++)
{
customTickLocations = [NSArray arrayWithObject:[NSDecimalNumber numberWithInt:i]];
}

请帮帮我,提前致谢,马丹

最佳答案

NSArray不可变的。使用可变版本 NSMutableArray

关于iphone - 如何使用 for 循环将对象添加到 NSArray?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7846201/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com