如何将一堆NSIntegers放入数组中?

时间:2017-09-16 00:19:59

标签: objective-c

我有三个NSInteger类型的变量,问题是你如何将NSInteger放入数组或数据集中?

- (void)someNumber {
    NSInteger one   = 1;
    NSInteger two   = 2;
    NSInteger three = 3;

    // how do you put the NSInteger in an array or data set?
}

2 个答案:

答案 0 :(得分:1)

只需制作NSArray个人吗?

NSArray *all = @[@(one), @(two), @(three)];

使用NSNumber运算符将它们装入@个对象。

答案 1 :(得分:0)

您必须将NSInteger作为NSNumber存储在NSArray中,如下所示

- (void)someNumber {
    NSInteger one   = 1;
    NSInteger two   = 2;
    NSInteger three = 3;

    // how do you put the NSInteger in an array or data set?
    NSArray *numberGroup = [NSArray arrayWithObjects:[NSNumber numberwithInteger:one],[NSNumber numberwithInteger: two],[NSNumber numberwithInteger: three]];
}