标题解释错误:
Unacceptable type of value for attribute: property = "routinename"; desired type = NSString; given type = _NSArrayM;
我正在添加一个数组,用户从中生成数组并将其导入核心数据实体。
这是由 :
viewDidLoad
NSMutableArray *array = [[NSMutableArray alloc] init];
self.exTitle = array;
didSelectRowAtIndexPath
[self.exTitle addObject: info.name];
一切正常并将值添加到数组中。
将其添加到我尝试过的核心数据实体中:
-(IBAction) Done: (id)sender {
NSManagedObjectContext *context = [self managedObjectContext];
NSManagedObject *newDevice = [NSEntityDescription insertNewObjectForEntityForName:@"Routines" inManagedObjectContext: context];
[newDevice setValue:exTitle forKey: @"routinename"];
我可能遗漏了一些非常简单的东西,但我该如何更正它,以便我可以将数组添加到实体中的 NSString 格式值中。
最佳答案
错误告诉您确切的问题所在。您的核心数据模型期望键“routinename”的对象类型是一个字符串。根据您发布的代码,extTitle
是一个数组。
要么修复数据模型,要么,如果需要,您可以编写一个方法将数组转换为字符串(尽管您可能应该转换为/自 NSData
对象)
关于ios - Not Acceptable 属性值类型 - 所需类型 NSstring,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17535456/