嗨,我将来自数据库的值保存在 MultableArray 中,然后保存在 CoreData 中:
NSMultableArray *mutary = [[NSMultableArray alloc] init];
NSManagedObjectContext *context = [app managedObjectContext];
for(int n=0; n<[AttributeArray count]; n++)
{
[mutary addObject:[[AttributeArray objectAtIndex:n] objectForKey:@"AttributName"]];
NSLog(@"%@", mutary);
}
attributeString = [mutary componentsJoinedByString:@","];
raume = [NSEntityDescription insertNewObjectForEntityForName:@"Raum" inManagedObjectContext:context];
raume.raumattribut = attributeString;
if (![context save:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
MultableArray 的 NSLog 输出为:
2012-06-20 17:21:00.047 book-app[31984:15803] (
A7OVERHEAD,
Beamer
)
到目前为止,它的工作正常。数据库中的两个预期值现在位于数组中。现在我从 CoreData 获取这些属性:
NSManagedObjectContext *context = [app managedObjectContext];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Raum" inManagedObjectContext:context];
[request setEntity:entity];
NSError *error = nil;
NSArray *events = [context executeFetchRequest:request error:&error];
for (Raum *att in events)
{
stringAttribute = [[events valueForKey:@"raumattribut"] componentsJoinedByString:@","];
NSLog(@"ATTRIBUTE: %@", stringAttribute);
}
}
到目前为止,一切都很好。但是,如果我现在查看我的 NSLog 输出:
2012-06-20 17:21:00.055 book-app[31984:15803] ATTRIBUTE: <null>,A7OVERHEAD,Beamer
CoreData 正在返回,然后是两个值。那是从哪里来的?
有人可以帮忙吗?
提前致谢