Objective-C valueforKey

rsp*_*eds 3 objective-c nsdictionary

我正在使用NSDictionary来存储设置值,我正在尝试将它们分配给double.但是我不知道该怎么做,valueforkey返回一个指针id.我尝试使用'*'获取实际值,但这不起作用.

这是代码

tempBrain.operand = [variables valueForKey:[(NSString*)obj  stringByReplacingOccurencesOfString:VARIABLE_PREFIX  withString:@""]];
Run Code Online (Sandbox Code Playgroud)

tempBrain.operand是double变量的setter方法.变量是我的NSDictionary.

Nic*_*ore 6

假设存储的值是一个NSNumber你可以这样使用doubleValue:

tempBrain.operand = [[variables objectForKey:[(NSString*)obj  stringByReplacingOccurencesOfString:VARIABLE_PREFIX  withString:@""]] doubleValue];
Run Code Online (Sandbox Code Playgroud)

另请注意,我已更改valueForKeyobjectForKey,这是用于从中获取对象的正确方法NSDictionary.