GData for iPhone无法使用编码器

时间:2011-06-28 11:09:17

标签: objective-c encoding nsdata gdata

在我写的日历应用中,我试图在本地保存日历数据以及使用谷歌服务器,但我没有太多运气。 [GDataEntryCalendarEvent encodeWithCoder:]会出现一个异常,似乎GData没有这样做。我使用的代码是 -

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 个答案:

答案 0 :(得分:1)

对于使用NSKeyedArchiver可归档的任何对象,其类必须符合NSCoding协议。 GDataEntryCalendarEvent不符合它,因此您收到此错误。您无法使用此方法保存内容。

要在本地保存GDataEntryCalendarEvent的实例,请查看this thread,其中提到了将其转换为可以在文件中写出的XML的方法。