【问题标题】:NSNumber in 64 bit architecture and Core Data64 位架构和核心数据中的 NSNumber
【发布时间】:2015-03-25 05:42:59
【问题描述】:

我在核心数据类中使用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 位架构)中运行良好。

有人遇到过这个问题吗?提前致谢。

【问题讨论】:

    标签: ios iphone core-data nsnumber


    【解决方案1】:

    对于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
    }
    

    【讨论】:

      猜你喜欢
      • 2013-11-14
      • 1970-01-01
      • 1970-01-01
      • 2011-01-11
      • 2012-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多