我的工作,將與我的iPad溝通和核心數據發送來回核心數據項目。我的網絡部分主要是想通了,但我有一個簡單的獲取請求行爲的問題。這裏是獲取請求:爲獲取請求,這不是獲取
NSManagedObjectContext *context=[[[NSDocumentController sharedDocumentController] currentDocument] managedObjectContext];
//NSManagedObjectContext *context=[self managedObjectContext];
if (context == nil){
NSLog(@"Crap");
}
NSLog(@"Context: %@",context);
//fetch request: (found here: http://developer.apple.com/library/ios/#documentation/DataManagement/Conceptual/iPhoneCoreData01/Articles/05_Fetching.html)
NSLog(@"Starting to fetch:");
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Song" inManagedObjectContext:context];
[request setEntity:entity];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"cueNo" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[request setSortDescriptors:sortDescriptors];
[sortDescriptors release];
[sortDescriptor release];
NSError *error;
NSMutableArray *mutableFetchResults = [[context executeFetchRequest:request error:&error] mutableCopy];
如果我用這個:
NSManagedObjectContext *context=[[[NSDocumentController sharedDocumentController] currentDocument] managedObjectContext];
然後我得到一個錯誤,指出:
+entityForName: could not locate an NSManagedObjectModel for entity name 'Song'
如果我用這個:
NSManagedObjectContext *context=[self managedObjectContext];
即使我有d,mutableFetchResults也會返回null ata在實體Song中。
我複製此直接從使用第一方法來設置情境以前的版本讀取請求它工作得很好那裏。
任何幫助將不勝感激!
故障排除:
Printing description of persistentStoreCoordinator:
Printing description of _managedObjectModel:
(<NSManagedObjectModel: 0x1001c5250>) isEditable 0, entities {
Song = "(<NSEntityDescription: 0x100149ba0>) name Song, managedObjectClassName NSManagedObject, renamingIdentifier Song, isAbstract 0, superentity name (null), properties {\n cueName = \"(<NSAttributeDescription: 0x1001c5600>), name cueName, isOptional 1, isTransient 0, entity Song, renamingIdentifier cueName, validation predicates (\\n), warnings (\\n), versionHashModifier (null), attributeType 700 , attributeValueClassName NSString, defaultValue (null)\";\n cueNo = \"(<NSAttributeDescription: 0x1001c5570>), name cueNo, isOptional 1, isTransient 0, entity Song, renamingIdentifier cueNo, validation predicates (\\n), warnings (\\n), versionHashModifier (null), attributeType 700 , attributeValueClassName NSString, defaultValue (null)\";\n}, subentities {\n}, userInfo {\n}, versionHashModifier (null)";
}, fetch request templates {
newFetchRequest = "<NSFetchRequest: 0x1001c5420> (entity: Song; predicate: (cueNo < \"0\"); sortDescriptors: (null); limit: 0)";
}
Printing description of _managedObjectContext:
<NSManagedObjectContext: 0x1001c5890>
非常感謝!我做了檢查,我沒有協調員或人力部。我現在做,模型包含歌曲實體。但我不確定如何將上下文與模型結合。任何幫助將不勝感激。 –
我今天做了更多的故障排除。我終於厭倦了沒有從我的抓取中獲得任何結果,並以編程方式添加數據。我終於得到了我需要的結果,但是揭示了IB未正確連接的問題。任何想法我能做些什麼來追蹤這個問題? –
我通過抓取並打印出變量「錯誤」的描述我得到了這個:打印錯誤描述: NSDocument如果我正確理解你,如果這個變量沒有正確,只會有問題嗎? –