0

I have this array and I want to access the first index inside another array.

(
    (
        1021,
        "String1,
        "<null>",
        "name1, name2",
        P,
        "String2",
        "Link1",
        "String3",
        "String4"
    ),
    (
        1025,
        "String1",
        "<null>",
        "name1, name2"
        P,
        "String2",
        "Link1",
        "String3",
        "String4"
    )
)

I tried to NSLog using this code:

NSLog(@"ID: %@", [[array objectAtIndex:0] objectAtIndex:0]);

But it doesn't work. It gives me an error saying:

-[__NSCFString objectAtIndex:]: unrecognized selector sent to instance

I just want to log the value 1021 in the first array of the first array.

2 Answers 2

6

The problem you are facing is that either array or the first element in array is a string.

Separate it out and step through with a debugger to make sure the array is being loaded and accessed correctly:

NSArray *array = [NSArray /* load from somwhere */];
NSLog(@"%@", array);

NSArray *innerArray = [array objectAtIndex:0];
NSLog(@"%@", innerArray);

NSNumber *objectId = [innerArray objectAtIndex:0];
NSLog(@"%@", objectId);
Sign up to request clarification or add additional context in comments.

Comments

1

This error indicates that the first object in array is an NSString.

Does any code add a string to said array?

If the first object in array were a dictionary, your code would be okay.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.