2

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.

Ivan Chaer
  • 6,980
  • 1
  • 38
  • 48
Tom
  • 269
  • 4
  • 14
  • Please post any details from the log about the crash. – Joe Aug 15 '11 at 14:16
  • Theres no error in the debug console, and in the file main.m it says "Thread 1: Program received signal: EXC_BAD_ACCESS". – Tom Aug 15 '11 at 14:19
  • You array may contain an over released object. Enable zombies and then post any additional details you may find. http://stackoverflow.com/questions/2190227/how-do-i-set-nszombieenabled-in-xcode-4 – Joe Aug 15 '11 at 14:20
  • I added an answer that may help you, if you still need further help you will need to post some code where you create and set the array. – Joe Aug 15 '11 at 14:47

2 Answers2

2

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 = ...'.

Joe
  • 56,979
  • 9
  • 128
  • 135
  • Thanks, that was the issue. I was releasing the array object further on in the code by mistake. – Tom Aug 15 '11 at 17:16
-1

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

Bill Burgess
  • 14,054
  • 6
  • 49
  • 86
  • According to the question the array looks to contain dictionaries so `objectForKey` is the correct way to access the value. There is not enough information provided to fully answer the question. (Anything stored in an NSArray or NSDictionary must be an object) – Joe Aug 15 '11 at 14:18
  • He is accessing an array of dictionaries. He is selecting the array, objectAtIndex (the dictionary), then the value for the item. While it is still an object, he would need to select the value of it for it to be useful. – Bill Burgess Aug 15 '11 at 15:46
  • The only difference with the dictionary for `valueForKey:` and `objectForKey:` is `valueForKey:` limits you to only use `NSString` keys. This answer just does not answer the OP question thats all, no down vote or anything just letting you know. – Joe Aug 15 '11 at 15:56
  • Yeah, you are right. Didn't know that valueForKey was limited to only NSString. Thanks for the heads up. – Bill Burgess Aug 15 '11 at 16:49