I’m porting an existing iOS app to Core Data (Xcode 5, Mavericks, iOS 7.1+). I need to import an existing sqlite3 database. I am auto-generating model files and then filling them with data from the database.
I have an auto-generated class that contains scalar types (I checked the Use Scalars box when auto-generating):
@interface Details : NSManagedObject
@property (nonatomic) float heightInches;
…
Auto-generation implements this property:
@implementation Details
@dynamic heightInches;
…
Then I try to set a value for this property using a float from the database:
Details* details = [NSEntityDescription insertNewObjectForEntityForName:@“Details” inManagedObjectContext:context];
[details setHeightInches:(float)sqlite3_column_double(statement, 10)];
…
When this line executes I get the following run-time error:
'NSInvalidArgumentException', reason: 'Unacceptable type of value for attribute: property = "heightInches"; desired type = NSNumber; given type = NSManagedObject; value = (entity: Details; id: 0x1002286a0 ; data: { heightInches = 0; …
I get the same run-time error if I redefine the implementation:
@synthesize heightInches;
And I get a compile-time error (type mismatch) if I try to pass in a NSNumber instead of a float:
[details setHeightInches:[NSNumber numberWithFloat:(float)sqlite3_column_double(statement, 10)]];
Why does Core Data expect an NSNumber when the data type is float? Why does Core Data see the float I’m passing in as NSManagedObject? The int32_t values seem to be working. Is there something special I have to do for floats?
Thanks