开发者

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

开发者 https://www.devze.com 2023-03-28 17:52 出处:网络
W开发者_开发知识库hen I NSLog the array I get this: ( { content = \"content a\"; id = 452069; timestamp = 1313341470;

W开发者_开发知识库hen 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消