JMD*_*JMD 5 core-data objective-c ios
我收到核心数据错误,我无法弄清楚如何修复.
我基本上将对象的所有数据都拉出到字典中,将数据显示到表单中,并且某些字段允许编辑,然后尝试在提交时将数据存储回对象.
但是,在设置所有新的/更新的值时,我得到错误
Unacceptable type of value for attribute: property = "totalLocations"; desired type = NSNumber; given type = __NSCFString; value = 7.
这是处理这个特定属性的代码......
//grab the value from the property
if (myObject.totalLocations)
[data setObject:myObject.totalLocations forKey:@"totalLocations"];
// store it back to the object
_myObject.totalLocations = [data objectForKey:@"totalLocations"];
Run Code Online (Sandbox Code Playgroud)
除了这两行外,没有太多的财产使用.它可以被修改,但不能被这个特定屏幕上的用户修改
totalLocations您的核心数据实体中的类型Integer是myObject.totalLocationsNSString吗?如果是,您应该像这样设置核心数据:
[data setValue:[NSNumber numberWithInteger:[myObject.totalLocations integerValue]] forKey:@"totalLocations"];
Run Code Online (Sandbox Code Playgroud)
我设置托管对象的方式是这样的:
- (void)insertNewPromo:(NSDictionary *)promoJson
{
NSManagedObjectContext *context = [self.promoFetchedResultsController managedObjectContext];
NSEntityDescription *entity = [[self.promoFetchedResultsController fetchRequest] entity];
NSManagedObject *newManagedObject = [NSEntityDescription insertNewObjectForEntityForName:[entity name] inManagedObjectContext:context];
// Checking if inappropriate data are in the JSON to avoid some crashes.
if ([[promoJson objectForKey:@"id"] isKindOfClass:[NSNull class]])
[newManagedObject setValue:nil forKey:@"id"];
else
[newManagedObject setValue:[NSNumber numberWithInteger:[[promoJson objectForKey:@"id"] integerValue]] forKey:@"id"];
...
...
NSError *error = nil;
if (![context save:&error])
{
if (DEBUG_ON == 1)
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
}
Run Code Online (Sandbox Code Playgroud)
所述id的对象promoJson是一个的NSString
| 归档时间: |
|
| 查看次数: |
5558 次 |
| 最近记录: |