-1

I had three variables of NSInteger type, the question is how do you put the NSInteger in an array or data set?

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

    // how do you put the NSInteger in an array or data set?
}
jscs
  • 63,694
  • 13
  • 151
  • 195
Sunny_Ken
  • 11
  • 4
  • 2
    What are you asking? What does "NSInteger of group" mean? Do you simply want to put your three variables in an `NSArray`? Why is the return value of `someNumber` set as `id`? You really need to clarify your question. Please [edit] your question with all clarifications. Do not post comments. – rmaddy Sep 16 '17 at 00:28
  • You are asking to return multiple values from a function like Swift `Tuple`. But it is not possible in objective c and you have to use `NSArray` or other collections. – Torongo Sep 16 '17 at 05:50
  • I am so sorry that, sometime you have some NSInteger type, I want to put some NSInteger variables into a data set. so do you have good idea? – Sunny_Ken Sep 16 '17 at 10:49
  • You can only put `(NS)Objects` into a `NSArray`. The simplest way is then to use `NSNumber`. – Larme Sep 16 '17 at 12:58

2 Answers2

1

Simply make an NSArray of them?

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

This boxes them into NSNumber objects using the @ operator.

vadian
  • 274,689
  • 30
  • 353
  • 361
zoul
  • 102,279
  • 44
  • 260
  • 354
0

You have to store the NSInteger as NSNumber in NSArray like bellow

- (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]];
}
Torongo
  • 1,021
  • 1
  • 7
  • 14