本文介绍了如何dyanmic通过CoreData模型创建一个新的实体(表)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在SQLite中创建一个新的Entity(表)。我的代码如下:
I want to create a new Entity (table) in SQLite. My code is 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]];
NSArray *properties = [CoreDataHelper CreateAttributes:attributes];
[entityDef setProperties:properties];
[entityDef release];
return TRUE;
}
但它会引发错误:
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 seems to show the model is read only.
推荐答案
(重点是我的)
这篇关于如何dyanmic通过CoreData模型创建一个新的实体(表)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!