Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在RestKit中,如何强制本地数据库与远程数据库匹配;大师;数据集_Ios_Sync_Restkit - Fatal编程技术网

Ios 在RestKit中,如何强制本地数据库与远程数据库匹配;大师;数据集

Ios 在RestKit中,如何强制本地数据库与远程数据库匹配;大师;数据集,ios,sync,restkit,Ios,Sync,Restkit,有没有一种简单的方法可以在RestKit与“主”远程数据集同步时强制它删除旧的本地项 因此,基本上是删除新数据集中未找到的元素吗?如果您使用的是RestKit 0.10,我只是添加了: [objectManager.mappingProvider setObjectMapping:eventsMapping forResourcePathPattern:@"data.xml" withFetch

有没有一种简单的方法可以在RestKit与“主”远程数据集同步时强制它删除旧的本地项


因此,基本上是删除新数据集中未找到的元素吗?

如果您使用的是RestKit 0.10,我只是添加了:

[objectManager.mappingProvider setObjectMapping:eventsMapping
                         forResourcePathPattern:@"data.xml"
                          withFetchRequestBlock:^NSFetchRequest *(NSString *resourcePath) {
                              return [Events fetchRequest];
                          }];
到我现有的代码。现在更新时,服务器上删除的所有对象都将从RestKit的managedObjects中删除

以下是整个过程:

// Set up the opjectManager
objectManager = [RKObjectManager objectManagerWithBaseURLString:kBaseUrlString];
objectManager.client.disableCertificateValidation = YES; // Using self signed cert
objectManager.client.cachePolicy = RKRequestCachePolicyLoadIfOffline | 
                                   RKRequestCachePolicyTimeout | 
                                   RKRequestCachePolicyLoadOnError | 
                                   RKRequestCachePolicyEtag;
objectManager.client.requestCache.storagePolicy = RKRequestCacheStoragePolicyPermanently;
objectManager.client.requestQueue.showsNetworkActivityIndicatorWhenBusy = YES;

// Set up the objectStore
RKManagedObjectStore* objectStore = [RKManagedObjectStore 
    objectStoreWithStoreFilename:databaseName 
           usingSeedDatabaseName:seedDatabaseName 
              managedObjectModel:nil 
                        delegate:self];
objectStore.delegate = self;
objectStore.cacheStrategy = [RKInMemoryManagedObjectCache new];

// Set up the event mapping (in my case, this is an XML file)
RKManagedObjectMapping *eventsMapping = [RKManagedObjectMapping mappingForEntityWithName:kEntityEvents 
                                                                    inManagedObjectStore:objectStore];
[eventsMapping mapKeyPath:@"contact" toAttribute:@"contact"];
[eventsMapping mapKeyPath:@"startDate" toAttribute:@"startDate"];
[eventsMapping mapKeyPath:@"endDate" toAttribute:@"endDate"];
[eventsMapping mapKeyPath:@"icon" toAttribute:@"icon"];
[eventsMapping mapKeyPath:@"location" toAttribute:@"location"];
[eventsMapping mapKeyPath:@"name" toAttribute:@"name"];
[eventsMapping mapKeyPath:@"notes" toAttribute:@"notes"];
[eventsMapping mapKeyPath:@"section" toAttribute:@"section"];
[eventsMapping mapKeyPath:@"url" toAttribute:@"url"];
eventsMapping.primaryKeyAttribute = @"name";

[objectManager.mappingProvider registerMapping:eventsMapping 
                               withRootKeyPath:@"root.events.event"];

// Added for RestKit upgrade from 0.9 to 0.10 to delete orphans (records not in GET)
[objectManager.mappingProvider setObjectMapping:eventsMapping 
                         forResourcePathPattern:@"data.xml" 
                          withFetchRequestBlock:^NSFetchRequest *(NSString *resourcePath) {
                              return [Events fetchRequest];
                          }];

// Load the opjects from XML file
[[RKObjectManager sharedManager] loadObjectsAtResourcePath:@"data.xml" 
                                                  delegate:self];

您将kBaseUrlString设置为什么来加载本地data.xml文件?