我正在將託管記錄的內容打印到文件中。我有一個主要實體,比如MyAppEntity和幾個相關的實體(人員,地點等)。coredata故障信息
我看到從該文件的輸出:
/Users/david/Library/Application Support/iPhone Simulator/5.1/Applications/C9ACA218-F2D6-4623-8CAF-5FE763D10FC8/Documents/
MyApp-0001 12.01.25
Summary goes here...
Nothing here yet.
Relationship 'people' on managed object (0x79eaf7f0) <NSManagedObject: 0x79eaf7f0> (entity: MyAppEntity; id: 0x79eae950 <x-coredata:/B86C9CA8-EDE4-452C-BA56-FEF50B4F0FF9/MyAppEntity/p1> ; data: {
audioName = 00010125121910;
audioNo = 0;
date = nil;
MyApp = "MyApp-0001 12.01.25";
interpret = "Nothing here yet.";
keyword = (
);
order = 0;
people = (
"0x79ee42f0 <x-coredata:/B86C9CA8-EDE4-452C-BA56-FEF50B4F0FF9/PeopleEntity/p1>",
"0x79ee4300 <x-coredata:/B86C9CA8-EDE4-452C-BA56-FEF50B4F0FF9/PeopleEntity/p2>"
);
place = (
"0x79ee6970 <x-coredata:/B86C9CA8-EDE4-452C-BA56-FEF50B4F0FF9/PlaceEntity/p2>",
"0x79ee6960 <x-coredata:/B86C9CA8-EDE4-452C-BA56-FEF50B4F0FF9/PlaceEntity/p1>"
);
recurring = 0;
summary = "Summary goes here...";
symbol = (
);
type = (
);
}) with objects {(
<NSManagedObject: 0x79ee47e0> (entity: PeopleEntity; id: 0x79ee42f0 <x-coredata:/B86C9CA8-EDE4-452C-BA56-FEF50B4F0FF9/PeopleEntity/p1> ; data: {
definition = nil;
name = me;
order = 0;
people = "<relationship fault: 0x79ef5ce0 'people'>";
}),
<NSManagedObject: 0x79ee4a70> (entity: PeopleEntity; id: 0x79ee4300 <x-coredata:/B86C9CA8-EDE4-452C-BA56-FEF50B4F0FF9/PeopleEntity/p2> ; data: {
definition = nil;
name = you;
order = 1;
people = "<relationship fault: 0x79e60840 'people'>";
})
)}
我有兩個問題。首先,什麼故障信息是什麼意思?第二,我如何檢索說people.name或place.name ..的值?
我可以張貼數據模型圖,但它基本上是這樣的:
MyAppEntity:屬性: 標題 日期 詳細 關係的人,地點等
PeopleEntity:屬性: 名稱 說明 訂購 關係:人
PlaceEntity:屬性: 名稱 說明 訂購 關係:地方
的關係是多對多。這是因爲一個任務可以有很多人,同一個人可以完成多項任務。
感謝Gerry和Marcus Zarra的另一個post。我終於得到它。如果它可以幫助別人,這是我的代碼:使用
NSManagedObjectContext *context = [self managedObjectContext];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *mainEntity = [NSEntityDescription entityForName:@"MainEntity" inManagedObjectContext:context];
[fetchRequest setEntity:mains];
NSError *error = nil;
NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&error];
NSLog(@"Record Count is: %i", [fetchedObjects count]);
// THIS ACTUALLY WORKS.....
for (MainEntity *mains in fetchedObjects) {
NSLog(@"Main: %@", mains.name);
NSSet *peopleSet = [mains valueForKey:@"people"];
for (id person in peopleSet) {
NSLog(@"name = %@", [person valueForKey:@"name"]);
}
NSSet *keywordSet = [mains valueForKey:@"keyword"];
for (id keyWord in keywordSet) {
NSLog(@"Keyword = %@", [keyWord valueForKey:@"word"]);
}
NSSet *placeSet = [mains valueForKey:@"place"];
for (id places in placeSet) {
NSLog(@"Place = %@", [places valueForKey:@"name"]);
}
NSSet *symbolSet = [mains valueForKey:@"symbol"];
for (id symbols in symbolSet) {
NSLog(@"Symbol = %@", [symbols valueForKey:@"symbolName"]);
}
NSSet *typeSet = [mains valueForKey:@"type"];
for (id types in typeSet) {
NSLog(@"Type = %@", [types valueForKey:@"typeName"]);
}
}
if (!fetchedObjects || error) {
NSLog(@"[ERROR] COREDATA: Fetch request raised an error - '%@'", [error description]);
return;
}
他們真的應該選擇一個其他錯誤的名稱。它引起了很多混亂(根據它出現在這裏的次數來判斷,無論如何!) – jrturton
謝謝Gerry。我還沒有喝咖啡,所以請原諒...我輸入了這段代碼:NSManagedObjectContext * context = [self managedObjectContext]; \t \t NSFetchRequest * fetchRequest = [[NSFetchRequest alloc] init]; \t NSEntityDescription *實體= [NSEntityDescription entityForName:@ 「AppEntity」 \t \t \t \t \t \t \t \t inManagedObjectContext:上下文]; \t [fetchRequest setEntity:entity]; NSLog(@「name =%@」,[person valueForKey:@「name」]);}};}};}};}}; \t} ---但實體。人們給我一個錯誤 - 屬性'人'沒有在'NSEntityDescription *'類型的對象上找到' –
非常感謝Gerry。通過我的英特爾4004大腦消化後,我明白你寫的是什麼。非常感謝...我已經在上面發佈了我的最終代碼。如果您發現問題,請告訴我。再次,我非常感謝。 –