<分区>
<分区>
Possible Duplicate:
Understanding NSString comparison in Objective-C
头文件:
@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模型也是string类型。
最佳答案
在你的代码中,你比较的是对象,但如果你想比较字符串,它应该是
if ([preference.pid isEqualToString:@"0"])
关于objective-c - 如何比较 coredata 字符串和 NSString,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14165412/
相关文章:
ios - 通知错误 : APN invalid token
ios - "pod install --verbose"错误
ios - Travis CI 问题 : Couldn't find the specified scheme in the mentioned workspace
ios - UITableViewCell 内的 UITextfield 文本在滚动时消失
objective-c - 如何将 std::string 转换为 NSString?
objective-c - NSTableViewDataSource 还是 NSArrayController?