gpt4 book ai didi

ios - 在 sprite kit Xcode 中创建一个整数数组

转载 作者:行者123 更新时间:2023-11-29 01:49:07 27 4
gpt4 key购买 nike

关于这个主题我真的没什么好说的,因为我找不到任何关于它的内容。我只想要一个整数数组,我可以引用我的 iOS 游戏中的项目价格。例如

Array priceArray = Array(50);

itemAPrice = Array (0);
itemBPrice = Array (1);

我知道它效率不高,但这纯粹是一个例子。任何有关在 sprite 工具包中创建整数/NSInteger 数组的主题都会有所帮助。

提前致谢-瑞安

最佳答案

NSArray 在 Objective-C 中是不可变的。您应该使用 NSMutableArray ,它是 NSArray 的子类:

// Create the array. Capacity is only a suggestion, not a hard limit
NSMutableArray * priceArray = [NSMutableArray arrayWithCapacity:50];

// You can't add doubles directly to the array. Wrap it inside NSNumber
[priceArray addObject:@0.0];
[priceArray addObject:@1.0];
// ...
[priceArray addObject:@49.0];

// Now get it back
double itemAPrice = [priceArray[0] doubleValue];
double itemBPrice = [priceArray[1] doubleValue];

关于ios - 在 sprite kit Xcode 中创建一个整数数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31600336/

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