서버에서 오는 모든 데이터가 관리되는 모델을 사용하여 핵심 데이터 관리 저장소에 기록되는 프로젝트를 설정했습니다. 전 모든 엔티티를 mogenerator를 사용하여 코어 데이터 모델에서 생성했습니다. 내 엔터티에 통합 된 모든 RestKit 매핑이 있습니다.RestKit 2.0 RKManagedObjectStore를 제거하지만 NSManagedObjectModel 유지
NSError *error = nil;
NSURL *modelURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"dataModel" ofType:@"momd"]];
// NOTE: Due to an iOS 5 bug, the managed object model returned is immutable.
NSManagedObjectModel *managedObjectModel = [[[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL] mutableCopy];
RKManagedObjectStore *managedObjectStore = [[RKManagedObjectStore alloc] initWithManagedObjectModel:managedObjectModel];
// Initialize the Core Data stack
[managedObjectStore createPersistentStoreCoordinator];
NSPersistentStore __unused *persistentStore = [managedObjectStore addInMemoryPersistentStore:&error];
NSAssert(persistentStore, @"Failed to add persistent store: %@", error);
[managedObjectStore createManagedObjectContexts];
// Set the default store shared instance
[RKManagedObjectStore setDefaultStore:managedObjectStore];
이제 시간 제약으로 인해 계획이 변경되었습니다. 데이터는 전혀 저장되어서는 안됩니다. 데이터는 서버에서 읽고 직접 표시해야합니다. 저장하지 않고 지속성이 없습니다. 그래서 RKManagedObjectStore를 잘라 내고 엔터티와 매핑을 유지하고 요청이 성공하거나 RKPaginator가 resutl되면 'RKMappingResult * mappingResult'에서 데이터를 읽으 려합니다. RKManagedObjectStore 및 RKPaginator 작동 예 : 나는 RKManagedObjectStore을 reomve하기 시작할 때
[objectManager addResponseDescriptor:[RKResponseDescriptor responseDescriptorWithMapping:[Friend entityMapping:objectManager.managedObjectStore]
method:RKRequestMethodAny
pathPattern:nil
keyPath:@"items"
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)]];
[objectManager setPaginationMapping:[self paginationMapping]];
self.paginator = [objectManager paginatorWithPathPattern:@"data"];
self.paginator.perPage = 20;
//Set completion block for this paginator
[self.paginator setCompletionBlockWithSuccess:^(RKPaginator *paginator, NSArray *objects, NSUInteger page) {
[weakSelf.dataArray addObjectsFromArray:objects];
} failure:^(RKPaginator *paginator, NSError *error) {
}];
그러나, 내가 때 매핑 문제로 돌아 가기 시작합니다.
'You must provide a managedObjectStore. Invoke mappingForClass:inManagedObjectStore: instead.'
Q.1 나는 Enitiy 매핑 RKManagedObjectStore없이 사용할 수 있습니까? 나는 올바른 방향으로 가고있다.
Q.2 상점을 제거하고 모델을 보관할 수 있습니까?
너무 복잡해지고 잘못된 방향으로 들어가기 전에 팁, 도움말 또는 예가 좋을 것입니다. 감사합니다
감사합니다. 나는 지금 MOC를 지키고 아주 가벼운 버전으로 작동하도록 노력할 것이다. – Alan