iPhone, how to dyanmic create new entity (table) via core data model?
Posted
by
Robin
on Stack Overflow
See other posts from Stack Overflow
or by Robin
Published on 2011-03-17T16:08:04Z
Indexed on
2011/03/17
16:09 UTC
Read the original article
Hit count: 213
iphone
as topic, I just want create new Entity(table) in sqlite ,
my code as follows:
+(BOOL)CreateDataSet:(NSManagedObjectModel *) model
attributes:(NSDictionary*)attributes
entityName:(NSString*) entityName
{
NSEntityDescription *entityDef = [[NSEntityDescription alloc] init];
[entityDef setName:entityName];
[entityDef setManagedObjectClassName:entityName];
[model setEntities:[NSArray arrayWithObject:entityDef]];
//@step
NSArray *properties = [CoreDataHelper CreateAttributes:attributes];
[entityDef setProperties:properties];
[entityDef release];
return TRUE;
}
but it throw errors:
Terminating app due to uncaught exception 'NSInternalInconsistencyException',
reason: 'Can't modify an immutable model.' * Call stack at first throw: ( 0 CoreFoundation 0x01c5abe9 __exceptionPreprocess + 185 1 libobjc.A.dylib 0x01daf5c2 objc_exception_throw + 47 2 CoreData 0x0152634a -[NSManagedObjectModel(_NSInternalMethods) _throwIfNotEditable] + 106 3 CoreData 0x01526904 -[NSManagedObjectModel setEntities:] + 36 ....
that seem show the model is read only.....
anyone can help on this problem? thanks
© Stack Overflow or respective owner