我有一個項目設置,來自服務器的所有數據都使用託管模型寫入Core Data託管商店。我使用mogenerator從Core Data模型生成了所有實體。我將所有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恢復時從「RKMappingResult * mappingResult」中讀取數據。例如,隨着RKManagedObjectStore和RKPaginator工作:
[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) {
}];
然而,當我開始reomve的RKManagedObjectStore我開始製作地圖時遇到問題。
'You must provide a managedObjectStore. Invoke mappingForClass:inManagedObjectStore: instead.'
Q.1我可以在沒有RKManagedObjectStore的情況下使用Enitiy Mapping嗎?我正朝着正確的方向前進嗎?
Q.2我可以刪除商店並保留模型嗎?
任何提示,幫助或示例都會很好,然後我會過度參與並且走錯方向。 謝謝Al
感謝您的信息。我現在將繼續保留MOC,並希望將它作爲一個非常輕量級的版本。 – Alan