简体   繁体   中英

How to refer to an object in a NSDictionary that is in a NSArray

When I NSLog the array I get this:

(
    {
        content = "content a";
        id = 452069;
        timestamp = 1313341470;
    },
        {
        content = "content b";
        id = 451498;
        timestamp = 1313261505;
    },
    etc...
)

How do you refer to specific index's? For example how would you get the content for the second index.

I've tried [[myArray objectAtIndex:1]objectForKey:@"content"] but that crashes the program.

Also doing [myArray objectAtIndex:1] crashes the program as well.

According to your edit your array is likely over released. Make sure your array is properly retained, if it uses a property make sure the property is set to copy or retain and if you set it internally be sure to use self.myArray =...; and not myArray =...' .

Have you tried -valueForKey: ? The item at that index is not an object but a value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM