저는 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];
을
mutableFetchResults는 내가 가지고 있어도 null을 반환합니다. 엔티티 송에서.
컨텍스트를 설정하는 첫 번째 방법을 사용하여이 가져 오기 요청을 이전 버전에서 직접 복사 했으므로 제대로 작동했습니다.
는 어떤 도움을 크게 감상 할 수있다!
문제 해결 :
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가 올바르게 연결되지 않았다는 문제가 밝혀졌습니다. 그 문제를 추적하기 위해 내가 무엇을 할 수 있는지 아는가? –
나는 가져 오기 단계를 밟았고 변수 "error"에 대한 설명을 출력했습니다. 오류의 인쇄 설명 : NSDocument이 변수가 올바르지 않으면 올바르게 이해할 수 있을까요? –