嗨,我現在的儲蓄從一個MultableArray數據庫未來值,然後在CoreData:CoreData中保存的字符串返回<null>和字符串。爲什麼?
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();
}
的NSLog輸出的MultableArray是:
2012-06-20 17:21:00.047 book-app[31984:15803] (
A7OVERHEAD,
Beamer
)
到目前爲止,它的工作正確。數據庫中的兩個期望值現在位於Array中。 現在我從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正在返回,然後兩個值。那來自哪裏?
有人可以幫忙嗎?
在此先感謝
如果我不喜歡它,它僅返回(空)。還有其他解決方案嗎? – Paks
我編輯了我的答案。雖然我不確定raumattribut屬性是什麼類型,並且componentsJoinedByString在那裏是適當的。 –
這不工作。我得到和錯誤: - [NSCFString componentsJoinedByString]無法識別的選擇器..「raumattribute」是一個NSString,你爲什麼要調用[att valueForKey:@「raumattribut」]而不是[events valueForKey:@「raumattribut」] – Paks