Tôi đã xem lại câu trả lời tại RestKit Object Mapping: difficulty using setObjectMapping:forResourcePathPattern:withFetchRequestBlock và đang hoạt động nhưng chỉ cho bản đồ cuối cùng. Ví dụ:RestKit xóa dữ liệu cũ khỏi dữ liệu lõi bằng cách sử dụng 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];
}];
Tất cả ánh xạ đang hoạt động tốt. Khi xml nguồn được cập nhật, các bản ghi mới sẽ được tạo. Khi tôi xóa một Event
, nó sẽ bị xóa. Khi tôi xóa một AudioSource
, nó sẽ không bị xóa.
Nếu tôi xóa số setObjectMapping:forResourcePathPattern:withFetchRequestBlock
thứ hai thì AudioSource
bị xóa chính xác, nhưng không xóa Event
. Tôi có 4 ánh xạ mà tôi đang làm việc với tệp xml này.
Giống như cuộc gọi cuối cùng đến setObjectMapping:forResourcePathPattern:withFetchRequestBlock
thắng.
Cách giải quyết của tôi là sử dụng setObjectMapping:forResourcePathPattern:withFetchRequestBlock
trên ánh xạ thay đổi thường xuyên nhất (trong trường hợp này là Events
) và thêm nút làm mất hiệu lực bộ nhớ cache, làm trống cơ sở dữ liệu và cập nhật. Phải có một cái gì đó đơn giản tôi đang mất tích.
Xcode: 4.3.3 RestKit: 0.10.1
Mẫu tập tin xml. Điều này tất cả tải trọng tốt, nhưng chỉ loại bỏ từ dữ liệu cốt lõi lập bản đồ bằng cách sử dụng cuối cùng 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 nguồn của bạn trông như thế nào? Liệu nó có , và tất cả dưới dạng thẻ lồng nhau không? –
@Steven Hepting - Tôi đã chỉnh sửa câu hỏi để thêm mẫu của tệp xml. Cảm ơn bạn đã hỏi thăm! – Kent
Bạn xóa mọi thứ bằng cách nào? bạn có thể thêm mã đó không? có thể một cuộc gọi đang bị ghi đè. Kiểm tra phản hồi của tôi để bạn có thể gỡ lỗi hành vi của dữ liệu lõi. – clopez