我这行代码,其中我试图将一个字符串的nsmutabledictinary内比较字符串:IOS中的NSMutableDictionary wtih字符串比较字符串我得到这个错误:“NSInvalidArgumentException”的
if ([[[myDictionary valueForKeyPath:@"time"] stringValue] isEqualToString:@"hours"])
,但我“M收到这个错误:
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString stringValue]: unrecognized selector sent to instance 0x3a4849a4'
我检查类字典容器的类型:
NSLog(@"%@'", NSStringFromClass([[myDictionary valueForKeyPath:@"time"] class]));
这是输出:
__NSCFConstantString
任何你知道这是为什么或如何解决这一问题?
我真的很感谢你的帮助。
既然你已经有一个字符串('NSString'),不叫'stringValue'就可以了。你真的要使用'valueForKeyPath:'而不是'objectForKey:'吗? – rmaddy
不能真的假设它是'NSString',但它在这种情况下似乎是这样。 –