我正在創建一個iOS應用程序,使用RestKit從Web服務器加載一些數據。RestKit/RKObjectMapping:在從服務器加載數據後,如何添加其他屬性?
它基於MSCollectionViewCalendarLayout。
的數據我加載具有以下結構(圖示爲了簡潔,只有1項):
{
"userID": "las404",
"items": [{
"id":"2000123",
"startTime":"2013-09-05T12:00:00",
"endTime":"2013-09-05T15:00:00",
"title":"Title",
"location":"Location",
"description":"Description"
}]
}
這是AttributeMapping
我用:
RKEntityMapping *eventMapping = [[RKEntityMapping alloc] initWithEntity:entity];
[eventMapping addAttributeMappingsFromArray:@[ @"title" ]];
[eventMapping addAttributeMappingsFromDictionary:@{
@"id" : @"id",
@"startTime" : @"start",
@"endTime" : @"end",
@"location" : @"location",
@"classID": @"classID"
}];
而我會喜歡做的是爲每個Core Data/SQLite記錄添加2個屬性; week
和userID
一旦數據已經加載,但之前它被添加到本地數據庫。
但我認爲它會不必要地「膨脹」我的JSON響應,如果我在每項目(約200)包括這個。那麼可以這樣做嗎?也許在[[RKObjectManager sharedManager] getObjectsAtPath...
?
我是一個完整的新手,當涉及到iOS/Obj-C開發所以任何幫助將不勝感激。
(另外:我試着看RestKit documentation但我怕我不明白大部分)
周是從開始/結束時間計算的? – Wain
@ Wain:的確如此。 – Lasse