我的工作,将与我的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如果我正确理解你,如果这个变量没有正确,只会有问题吗? –