views:

258

answers:

3
 NSDictionary *topic = [spaces objectAtIndex:i];
 NSInteger topicid = [topic valueForKey:@"TOPICID"];

when I run this and print out topic I get the following:

Printing description of topic:
<CFDictionary 0xdb2a70 [0x30307a00]>{type = mutable, count = 2, capacity = 12, pairs = (
    10 : <CFString 0xdb5300 [0x30307a00]>{contents = "TOPICID"} = 29
    12 : <CFString 0xdb53a0 [0x30307a00]>{contents = "TOPICNAME"} = <CFString 0xdb5360 [0x30307a00]>{contents = "zzzzzzzz"}
)}

However, when I look at topicid, the value is always a memory address. What am I doing wrong?

+3  A: 

Maybe the value is actually an NSNumber. You would get this using:

NSInteger topicid = [[topic objectForKey:@"TOPICID"] intValue];
Xetius
A: 

Dictionaries can only contain objects, not primitives. Whatever is stored in there (as Xetius suggested) is probably wrapped in some form. It would appear that TOPICID is an NSString.

Ben Gottlieb
doesn't the description output indicate that the key is a string and the value is simply 29 (no type defined)?
pxl
The description is 'pretty printed'; there's no way to store a raw integer in a dictionary
Ben Gottlieb
A: 

In the array output, you can see topicID is a string value (NSString). So, you would want to set it as Xetius describes - but not because it is an NSNumber, because NSString has an "intValue" method.

Kendall Helmstetter Gelner