objective-c - 如何比较 coredata 字符串和 NSString

标签 objective-c ios xcode core-data

<分区>

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/

上一篇:objective-c - iOS 将图像拉伸(stretch)到全屏

下一篇:objective-c - 检测绘制图像的百分比是 "erased"

相关文章:

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?

java - 制作网络服务,采用哪种方法?

ios - 检查翻转卡片后的相同图像(objective-C)

ios - 在 xcode/模拟器中启用 iPad pro

ios - 核心蓝牙 : Send data between 2 iOS devices