답변을 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
을 사용하고 캐시를 무효화하고 데이터베이스를 비우고 업데이트하는 버튼을 추가하십시오. 내가 누락 된 단순한 것이 있어야합니다.
엑스 코드 : 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은 어떤 모습입니까? 및 가 모두 중첩 된 태그로 이 있습니까? –
@Steven Hepting - xml 파일의 샘플을 추가하는 질문을 편집했습니다. 물어봐 줘서 고마워! – Kent
어떻게 삭제하고 있습니까? 그 코드를 추가 할 수 있습니까? 아마 하나의 전화를 덮어 씁니다. 핵심 데이터의 동작을 디버깅 할 수 있도록 내 응답을 확인하십시오. – clopez