64 位架构和 Core Data 中的 NSNumber
NSNumber in 64 bit architecture and Core Data
我在我的核心数据 class 中使用 NSNumber
作为 属性,如下所示。
@property (nonatomic, retain) NSNumber * favStatus;
在实际应用中,我检索对象并将其存储在循环中的字典中,并将它们添加到数组中。
NSMutableDictionary *msgDictionary = [[NSMutableDictionary alloc] init];
Deal *obj=(Deal *)[fetchedDealObjects objectAtIndex:i];
msgDictionary=[NSMutableDictionary dictionaryWithObjectsAndKeys:
obj.dealId, @"dealId",
obj.dealName, @"dealName",
obj.senderName, @"senderName",
obj.dealMessage, @"dealMessage",
obj.imageStatus, @"imageStatus",
obj.imageName, @"imageName",
obj.dealType, @"dealType",
obj.remindStatus, @"remindStatus",
obj.readStatus, @"readStatus",
obj.dealdate,@"dealDate",
obj.favStatus, @"favStatus",
obj.dealAddr,@"dealAddr",
//obj.dealdate,@"dealDate",
obj.dealEndDate,@"dealEndDate",
nil];
现在我使用循环读取数组并检查 favStatus
字段的值,如下所示。
if ([[allDealsArray objectAtIndex:indexPath.row]valueForKey:@"favStatus"]==[NSNumber numberWithInt:0]) {
//number 0 found in core data
}else{
//number 0 not found in the core data
}
我的问题是虽然核心数据表中的值是 0
,但 64 位架构的手机不会将它们识别为 0。它总是转到 else 块。
但它在 iPhone 5 和以前的模型(非 64 位架构)中工作得很好。
有人遇到过这个问题吗?提前致谢。
对于 NSNumber
,您应该使用 isEqualToNumber:
方法而不是 '=='
。
在这种情况下,我认为您应该尝试:
int favStatusVal = [[[allDealsArray objectAtIndex:indexPath.row]valueForKey:@"favStatus"] intValue];
if (favStatusVal == 0) {
//number 0 found in core data
}else{
//number 0 not found in the core data
}
我在我的核心数据 class 中使用 NSNumber
作为 属性,如下所示。
@property (nonatomic, retain) NSNumber * favStatus;
在实际应用中,我检索对象并将其存储在循环中的字典中,并将它们添加到数组中。
NSMutableDictionary *msgDictionary = [[NSMutableDictionary alloc] init];
Deal *obj=(Deal *)[fetchedDealObjects objectAtIndex:i];
msgDictionary=[NSMutableDictionary dictionaryWithObjectsAndKeys:
obj.dealId, @"dealId",
obj.dealName, @"dealName",
obj.senderName, @"senderName",
obj.dealMessage, @"dealMessage",
obj.imageStatus, @"imageStatus",
obj.imageName, @"imageName",
obj.dealType, @"dealType",
obj.remindStatus, @"remindStatus",
obj.readStatus, @"readStatus",
obj.dealdate,@"dealDate",
obj.favStatus, @"favStatus",
obj.dealAddr,@"dealAddr",
//obj.dealdate,@"dealDate",
obj.dealEndDate,@"dealEndDate",
nil];
现在我使用循环读取数组并检查 favStatus
字段的值,如下所示。
if ([[allDealsArray objectAtIndex:indexPath.row]valueForKey:@"favStatus"]==[NSNumber numberWithInt:0]) {
//number 0 found in core data
}else{
//number 0 not found in the core data
}
我的问题是虽然核心数据表中的值是 0
,但 64 位架构的手机不会将它们识别为 0。它总是转到 else 块。
但它在 iPhone 5 和以前的模型(非 64 位架构)中工作得很好。
有人遇到过这个问题吗?提前致谢。
对于 NSNumber
,您应该使用 isEqualToNumber:
方法而不是 '=='
。
在这种情况下,我认为您应该尝试:
int favStatusVal = [[[allDealsArray objectAtIndex:indexPath.row]valueForKey:@"favStatus"] intValue];
if (favStatusVal == 0) {
//number 0 found in core data
}else{
//number 0 not found in the core data
}