标题文件:
@property (nonatomic, strong) NSString *pid;
@property (nonatomic, strong) NSString *name;
存储Coredata NSString:
[newPref setValue: @"0" forKey:@"pid"]; //correctly show in DB & NSLog
[newPref setValue: @"Sales" forKey:@"name"];
稍后检索后,评估失败:
if(preference.pid == @"0")
调试器说:
_pid = (NSSting *) 0x... @"o\xee\"
_name = (NSString *) )x0.. @<variable is not NSString>
我存储的NSString是不正确的,还是我的评价错了? 注意:Coredata模型也是类型字符串。
答案 0 :(得分:2)
在您的代码中,您正在比较对象,但如果您想比较字符串,那么它应该是
if ([preference.pid isEqualToString:@"0"])