2012-10-01 31 views
1

與Core Data一起使用時,RestKit的刪除語義是什麼?RestKit刪除語義

例如,假設我在組織實體的RestKit中正確設置了primaryKeyAttribute。如果我做了一個GET,比如說,/organizations/我得到/organizations/1//organizations/2//organizations/3/的回來。假設我稍後在/organizations/上進行GET,並且僅返回/organizations/1//organizations/3/的條目。 `/ organizations/2 /已被刪除在服務器上。

我希望RestKit刪除我的核心數據記錄/organizations/2/。這是RestKit做的還是我必須實現這種行爲?如果我使用reboot-networking-layer分支,這是否會以任何方式更改? RestKit中有任何設置我應該知道這會影響此行爲嗎?

回答

2

您需要實現FetchRequests才能刪除這些對象。這裏有一個簡單的例子:

[objectManager addFetchRequestBlock:^NSFetchRequest *(NSURL *URL) { 
    RKPathMatcher *pathMatcher = [RKPathMatcher pathMatcherWithPattern:@"/organizations"]; 

    NSDictionary *argsDict = nil; 
    BOOL match = [pathMatcher matchesPath:[URL relativePath] tokenizeQueryStrings:NO parsedArguments:&argsDict]; 

    if (match) { 
     NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"Organization"]; 
     return fetchRequest; 
    } 

    return nil; 
}]; 

我在ApplicationDelegate(安裝RestKit的同一個地方)這樣做。在此之後,所有其他呼叫將自動刪除孤立的對象。