L
L
Lorem Ipsum2014-09-18 17:16:40
Objective-C
Lorem Ipsum, 2014-09-18 17:16:40

How to return one element of an array objective-c ?

Unable to return 1 array element. Xcode does not give errors, but after launching the application closes and sends me to main ()

//массив
  NSArray *data = [NSJSONSerialization JSONObjectWithData:receviedData options:kNilOptions error:nil];
    NSLog(@"%@", data);
    //const, в которую надо сохранить один элемент массива
    token = [data objectAtIndex:1];
    //вывожу на экран 
    self.resultDict.text = token;

what could be the problem ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
agee, 2014-09-19
@GeorgeGeorge

When you are "sent to main()" - this is a clear sign that there is an error. And it is displayed in XCode below in the log output panel. The call stack will also be displayed there. Go through the tracer and find out on which line the exception was thrown.
If the error is in the line token = [data objectAtIndex:1], make sure that:
- JSONObjectWithData returns exactly an array object, and not, say, a dictionary (potentially throws an NSInvalidArgumentException error when calling doesNotRecognizeSelector);
- in the returned array, if it is an array, more than 1 element (an NSRangeException may pop up if you take the 2nd element, and there, let's say, there is only one).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question