core-datansinteger

Reading integer from Core Data


In my app I have a Core Data entity called Status with two attributes messageID as Integer32 and messageText as String.

I have a string stored in an SQL database which the app downloads on startup. The string from the database is broken down into two parts ID and text. An example message could be 011-Hello and the each part is stored in an array called messageParts. The first item in the array is the ID:

NSInteger newMessageID = [messageParts[0] integerValue];

I want to compare this ID with the one stored in Core Data such as:

if (messageID == newMessageID)

I get the newMessageID fine and I have a number to work with but I am totally confused as to how to handle the data type coming from Core Data. I can see that there is a number in the database using SQLlitebrowser and I have tried:

NSInteger *savedMessageID = [[self.status objectAtIndex:0] messageID]; 

and

NSInteger savedMessageID = [[self.status objectAtIndex:0] messageID]; 

But neither return the stored value. I think that this is a pointer issue but I am going around in circles here.


Solution

  • If you generate the NSManagedObject subclass from your xcdatamodeld (Xcode menu Editor > Create NSManagedObject Subclass…), you will find that the integer32 field is generated as an NSNumber...

    This is maybe where you should take a look ?