ValueForKey returns only the memory address, not the value

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

when I run this and print the theme, 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 a topic, the value is always the memory address. What am I doing wrong?

+3
source share
3 answers

Perhaps the value is an NSNumber. You will get this using:

NSInteger topicid = [[topic objectForKey:@"TOPICID"] intValue];
+7
source

Dictionaries can only contain objects, not primitives. Everything that is stored there (as Ksitsiy suggested) is probably wrapped in some form. It looks like TOPICID is an NSString.

0
source

, topicID (NSString). , Xetius. - , NSNumber, NSString "intValue"

0

Source: https://habr.com/ru/post/1720187/


All Articles