Created
April 22, 2015 22:20
-
-
Save 3lvis/d84020ba97bb7f16c0a5 to your computer and use it in GitHub Desktop.
Generating a Core Data Model from code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)generateModel { | |
NSManagedObjectModel *model = [NSManagedObjectModel new]; | |
NSEntityDescription *runEntity = [NSEntityDescription new]; | |
runEntity.name = @"Run"; | |
runEntity.managedObjectClassName = @"Run"; | |
model.entities = @[runEntity]; | |
NSMutableArray *runProperties = [NSMutableArray new]; | |
NSAttributeDescription *dateAttribute = [NSAttributeDescription new]; | |
dateAttribute.name = @"date"; | |
dateAttribute.attributeType = NSDateAttributeType; | |
dateAttribute.optional = NO; | |
[runProperties addObject:dateAttribute]; | |
NSAttributeDescription *idAttribute= [NSAttributeDescription new]; | |
idAttribute.name = @"processID"; | |
idAttribute.attributeType = NSInteger32AttributeType; | |
idAttribute.optional = NO; | |
idAttribute.defaultValue = @0; | |
[runProperties addObject:idAttribute]; | |
NSPredicate *validationPredicate = [NSPredicate predicateWithFormat:@"SELF >= 0"]; | |
NSString *validationWarning = @"Process ID < 0"; | |
[idAttribute setValidationPredicates:@[validationPredicate] | |
withValidationWarnings:@[validationWarning]]; | |
runEntity.properties = runProperties; | |
NSDictionary *localizationDictionary = @{@"Property/processID/Entity/Run" : @"Process ID", | |
@"Property/date/Entity/Run" : @"Date", | |
@"ErrorString/Process ID < 0" : @"Process ID must not be less than 0"}; | |
model.localizationDictionary = localizationDictionary; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment