title: Data type mismatch in xcode core data class
body: <p>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.</p>
  
  <p>I have an auto-generated class that contains scalar types (I checked the Use Scalars box when auto-generating):</p>
  
  <pre><code>@interface Details : NSManagedObject
  
  @property (nonatomic) float heightInches;
  …
  </code></pre>
  
  <p>Auto-generation implements this property:</p>
  
  <pre><code>@implementation Details
  
  @dynamic heightInches;
  …
  </code></pre>
  
  <p>Then I try to set a value for this property using a float from the database:</p>
  
  <pre><code>Details* details = [NSEntityDescription insertNewObjectForEntityForName:@“Details” inManagedObjectContext:context];
  [details setHeightInches:(float)sqlite3_column_double(statement, 10)];
  …
  </code></pre>
  
  <p>When this line executes I get the following run-time error:</p>
  
  <blockquote>
    <p>'NSInvalidArgumentException', reason: 'Unacceptable type of value for
    attribute: property = "heightInches"; desired type = NSNumber; given
    type = NSManagedObject; value = 
    (entity: Details; id: 0x1002286a0
     ; data:
    {
        heightInches = 0; …</p>
  </blockquote>
  
  <p>I get the same run-time error if I redefine the implementation:</p>
  
  <pre><code>@synthesize heightInches;
  </code></pre>
  
  <p>And I get a compile-time error (type mismatch) if I try to pass in a NSNumber instead of a float:</p>
  
  <pre><code>[details setHeightInches:[NSNumber numberWithFloat:(float)sqlite3_column_double(statement, 10)]];
  </code></pre>
  
  <p>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?</p>
  
  <p>Thanks</p>