Problem while looping on a NSDictionary

Posted by Tom on Stack Overflow See other posts from Stack Overflow or by Tom
Published on 2010-04-08T15:03:12Z Indexed on 2010/04/08 15:13 UTC
Read the original article Hit count: 279

Filed under:
|
|

Hi!

The end of my loop causes a EXC_BAD_ACCESS.

Here's my dictionary (AppDelegate.data):

1 =     (
    3,
    "Test 1",
    False,
    ""
);
2 =     (
    4,
    "Test 2",
    False,
    ""
);

And here is my loop:

   for (id theKey in AppDelegate.data) {
        if (theKey = nil) {
            NSLog(@"HOLY COW");
        } else {
            NSLog(@"Key: %@ ?", theKey);
        }           
    }

It never says holy cow, and it says the right key but at the end it crashes...

Do you have any idea why? It should only loop on 1 and two and then exit the loop... I know that there's always a "nil" object at the end that's why I did a condition with it but it doesn't look like it works at all..

Thanks!

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about cocoa-touch