Reshan Auston
Reshan Auston

Reputation: 59

NSNumber in 64 bit architecture and Core Data

I have used NSNumber as property in my core data class as shown below.

@property (nonatomic, retain) NSNumber * favStatus;

In real application I retrieve and store the object in a dictionary as below within a loop and add them to an Array.

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];

Now I read the array using a loop and checking the values as below for the favStatus field.

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
}

My problem is though the values are 0 in core data tables, 64 bit architecture phones doesn't recognize them as 0. It always goes to the else block.

But it works just fine in iPhone 5 and previous models (non 64 bit architecture).

Has anyone encountered this issue? Thanks in advance.

Upvotes: 0

Views: 88

Answers (1)

Huy Nghia
Huy Nghia

Reputation: 986

With NSNumber you should use isEqualToNumber: method instead of '=='.
In this case I think you should try:

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
}

Upvotes: 1

Related Questions