2012-07-11 3 views
10

답변을 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> 
+1

원본 XML은 어떤 모습입니까? 가 모두 중첩 된 태그로 이 있습니까? –

+0

@Steven Hepting - xml 파일의 샘플을 추가하는 질문을 편집했습니다. 물어봐 줘서 고마워! – Kent

+0

어떻게 삭제하고 있습니까? 그 코드를 추가 할 수 있습니까? 아마 하나의 전화를 덮어 씁니다. 핵심 데이터의 동작을 디버깅 할 수 있도록 내 응답을 확인하십시오. – clopez

답변

2

내가 전에 관리 오브젝트를 사용하지 않은 그러나 여기에서 할 수있는 제일 먼저 객체 매핑을 통해 restkit 로그를 활성화하기 위해, 네트워크로 사용하는 매핑을 삭제 요청 및 핵심 데이터는 CD에서 물건을 가져 오는 방법을 매핑 작업과 방법을 서버에서 점점 restkit가 무엇인지 확인, 그래서 다음 시도 할 수 있습니다 : 당신은을 사용하는

//This can be added in your app delegate 
RKLogConfigureByName("RestKit/Network", RKLogLevelTrace); 
RKLogConfigureByName("RestKit/ObjectMapping", RKLogLevelTrace); 
RKLogConfigureByName("RestKit/CoreData", RKLogLevelTrace); 

이 코드를보고 여기에있는 두 매핑의 동일한 경로 :

(210) 나는 RK 모두 자원 중 하나가 해당 경로에 매핑 할 선택 때문에이 충돌의 원인이 될 수 있다고 생각합니다, 그래서 당신은해야한다 :

  1. 디버그 코어 데이터 일 것입니다.
  2. 리소스 경로 패턴 대신 키 경로 접근 방식에 대한 매핑을 사용하여 RK가 엉망이되지 않도록해야합니다. 각 객체 종류를 매핑하는 여러 가지 방법을 정의해야합니다. 처음에는 덮어 쓰는 것 같습니다. .

그래도 작동하지 않으면 코드에서 항목을 삭제하는 방법을 게시하고,보기 컨트롤러에서 모든 코드를 게시 할 수 있습니다. 일어날 수있는 일은 호출이 어딘가에서 코드에 의해 덮어 쓰여지고 있다는 것입니다. 블록을 사용하고 있습니까?

희망 하시겠습니까?

+0

로그 메시지가 출력됩니다. 나는 코드에서 삭제하지 않는다. xml을 편집하고 요소를 제거하면 다음 번에 요소를 제거해야합니다. 그것은 마지막'mappingProvider'에서 작동합니다. 내가 사용하고있는 유일한 블록은 위의'withFetchRequestBlock'에 있습니다. 핵심 접근 방식에 대한 매핑을 살펴보고 결과를 다시 살펴 보겠습니다. 고맙습니다. – Kent

+0

그런 작업을 수행 할 때 핵심 데이터 로그의 출력은 무엇입니까? – clopez

관련 문제