Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell Core Data's NSNumber property's type

I have an iOS 4 project using Core Data. When I design the Core Data Model, the attributes have Integer 64, Integer 32, Integer 16, Decimal, Double, Float, and Boolean.

But in the generated NSManagedObject subclasses, they are all NSNumber*. So when I use it, how can I tell if that NSNumber is a long, a double, a float, or a BOOL?

like image 858
Zhao Xiang Avatar asked Apr 21 '11 14:04

Zhao Xiang


1 Answers

NSEntityDescription *entity = [NSEntityDescription entityForName:@"MyEntity" inManagedObjectContext:myManagedObjectContext];
NSAttributeDescription *attribute = [[entity attributesByName] objectForKey:@"myAttribute"];
if ([attribute attributeType] == NSInteger32AttributeType) {
    // We have an Integer32
    // ...
}

Check the NSAttributeDescription.h header for other valid attribute types besides NSInteger32AttributeType.

like image 158
Ole Begemann Avatar answered Sep 22 '22 07:09

Ole Begemann