He revisado la respuesta en RestKit Object Mapping: difficulty using setObjectMapping:forResourcePathPattern:withFetchRequestBlock y está funcionando, pero solo para la última asignación. Ejemplo:RestKit eliminar los datos antiguos de los datos principales utilizando 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];
}];
Todas las asignaciones funcionan a la perfección. Cuando se actualiza el xml fuente, se crean nuevos registros. Cuando elimino un Event
, se elimina. Cuando elimino un AudioSource
, no se borra.
Si elimino el segundo setObjectMapping:forResourcePathPattern:withFetchRequestBlock
, entonces el AudioSource
se borra correctamente, pero el Event
borrado no lo está. Tengo 4 mapeos con los que estoy trabajando en este archivo xml.
Es como la última llamada a setObjectMapping:forResourcePathPattern:withFetchRequestBlock
gana.
Mi solución consiste en utilizar el setObjectMapping:forResourcePathPattern:withFetchRequestBlock
en la asignación que cambia más a menudo (en este caso, el Events
) y agregar un botón que invalide el caché, vacíe la base de datos y actualice. Debe haber algo simple que me falta.
Xcode: archivo XML 0.10.1
muestra: 4.3.3 RestKit. Todo esto cargas muy bien, pero sólo elimina a partir de datos básicos de la asignación utilizando la última 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>
¿Cómo es su XML fuente? ¿Tiene , y como etiquetas anidadas? –
@Steven Hepting: he editado la pregunta para agregar una muestra del archivo xml. ¡Gracias por preguntar! – Kent
¿Cómo estás borrando cosas? ¿Puedes agregar ese código? probablemente se sobrescriba una llamada. Verifique mi respuesta para que pueda depurar el comportamiento de los datos centrales. – clopez