2011-06-28 42 views
0

在我正在編寫的日曆應用程序中,我試圖在本地保存日曆數據以及使用Google服務器,但我沒有太多運氣。 [GDataEntryCalendarEvent encodeWithCoder:]引發一個異常,看起來GData不這樣做。我使用的代碼 -GData for iPhone無法使用編碼器

NSMutableData *data = [[NSMutableData alloc] init]; 
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data]; 

int keyNum = 1; 
for (NSArray *eventsInfo in [calendarData allValues]) { 
    NSString *theKey = [NSString stringWithFormat:@"%i",keyNum]; 
    [archiver encodeObject:eventsInfo forKey:theKey]; 
    keyNum ++; 
} 

[archiver finishEncoding]; 

bool success = [data writeToFile:[Directories calendarDataFilePath] atomically:YES]; 

[archiver release]; 
[data release]; 

bool success = [calendarData writeToFile:[Directories calendarDataFilePath] atomically:YES]; 
NSLog(@"Calendar Data saved: %@",success); 

,我得到的錯誤是 - [GDataEntryCalendarEvent encodeWithCoder:]:無法識別的選擇發送到實例0x4d60b40

感謝您的幫助!

回答

1

對於任何需要使用NSKeyedArchiver進行存檔的對象,其類必須符合NSCoding協議。 GDataEntryCalendarEvent不符合它,所以你得到這個錯誤。您不能使用此方法來保存內容。

要在本地保存GDataEntryCalendarEvent的實例,請參閱this thread,其中提到了將其轉換爲可以寫入文件的XML的方法。

+0

非常感謝這個鏈接 - 我發現在GData上找到好的文檔非常困難,所以這將非常有用。 – SomaMan

相關問題