我已閱讀RestKit Object Mapping: difficulty using setObjectMapping:forResourcePathPattern:withFetchRequestBlock的答案,它正在工作,但僅適用於最後的映射。例如:RestKit使用setObjectMapping從核心數據中刪除舊數據
RKManagedObjectMapping *audioSourcesMapping = [RKManagedObjectMapping mappingForEntityWithName:kEntityAudioSources inManagedObjectStore:objectStore];
[audioSourcesMapping mapKeyPath:@"icon" toAttribute:@"icon"];
[audioSourcesMapping mapKeyPath:@"name" toAttribute:@"name"];
[audioSourcesMapping mapKeyPath:@"notes" toAttribute:@"notes"];
[audioSourcesMapping mapKeyPath:@"section" toAttribute:@"section"];
[audioSourcesMapping mapKeyPath:@"url" toAttribute:@"url"];
audioSourcesMapping.primaryKeyAttribute = @"name";
[wsiObjectManager.mappingProvider registerMapping:audioSourcesMapping withRootKeyPath:@"winSystem.winSystemAudioSources.winSystemAudioSource"];
[wsiObjectManager.mappingProvider setObjectMapping:audioSourcesMapping forResourcePathPattern:kWinSystemInfoXml
withFetchRequestBlock:^NSFetchRequest *(NSString *resourcePath) {
return [AudioSources fetchRequest];
}];
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";
[wsiObjectManager.mappingProvider registerMapping:eventsMapping withRootKeyPath:@"winSystem.winSystemEvents.winSystemEvent"];
[wsiObjectManager.mappingProvider setObjectMapping:eventsMapping forResourcePathPattern:kWinSystemInfoXml
withFetchRequestBlock:^NSFetchRequest *(NSString *resourcePath) {
return [Events fetchRequest];
}];
所有的映射工作都很好。當源XML更新時,將創建新記錄。當我刪除Event
時,它會被刪除。當我刪除一個AudioSource
它不會被刪除。
如果我刪除第二個setObjectMapping:forResourcePathPattern:withFetchRequestBlock
那麼AudioSource
被正確刪除,但刪除的Event
不是。我在這個XML文件中使用了4個映射。
這就像是最後一次致電setObjectMapping:forResourcePathPattern:withFetchRequestBlock
獲勝。
我的解決方法是在最常更改的映射(本例中爲Events
)上使用setObjectMapping:forResourcePathPattern:withFetchRequestBlock
,並添加一個按鈕,使緩存無效,清空數據庫並更新。一定有一些簡單的我錯過了。
的Xcode 4.3.3 RestKit:0.10.1
示例XML文件。這一切都加載罰款,但是從核心數據,只是將使用最後setObjectMapping:forResourcePathPattern:withFetchRequestBlock
<?xml version="1.0" encoding="UTF-8"?>
<winSystem>
<winSystemAudioSources>
<winSystemAudioSource
icon="audio.png"
name="Hub Audio"
notes="Cleaner Sound. Audio is delayed by about 30 seconds. This is a great way to see if you are making into the WIN System."
section=" WIN System"
url="http://stream.winsystem.org:443/2560.mp3" />
</winSystemAudioSources>
<winSystemEvents>
<winSystemEvent
contact=""
endDate=""
icon="net.png"
location="WIN System reflector 9100"
name="Insomniac Trivia Net"
notes="Every Night @ 23:00 PT - WIN System reflector 9100. Join the Yahoo! group: http://groups.yahoo.com/group/insomniac-net/join"
section="Ham Nets"
startDate=""
url="http://www.thedeanfamily.com/WinSystem/InsomniacNet.htm" />
</winSystemEvents>
<winSystemLinks>
<winSystemLink
icon="winsystem.png"
name=" WIN System Home Page"
notes="The WIN System Home Page"
section=" WIN System"
type="web"
url="http://www.winsystem.org/" />
</winSystemLinks>
<winSystemRepeaters>
<winSystemRepeater
callSign="K6JSI"
freqOffsetPl="448.800* (-) 100.0"
grouping="winsystem"
latitudeDefault=""
locationElevation="Shorty's house, 560' + 53'"
longitudeDefault=""
node="A 01330"
repeaterId="1"
serviceArea="Vista"
serviceState="CA" />
</winSystemRepeaters>
</winSystem>
你的XML源代碼是什麼樣的?它是否有 , 和 全都作爲嵌套標籤? –
2012-08-19 01:52:04
@Steven Hepting - 我編輯了這個問題來添加一個xml文件的樣本。謝謝你的慰問! – Kent 2012-08-20 03:21:19
你如何刪除東西?你可以添加代碼嗎?可能有一個電話被覆蓋。檢查我的響應,以便調試核心數據的行爲。 – clopez 2012-08-23 14:07:36