iPhone 版 GData 无法使用编码器
在我正在编写的日历应用程序中,我尝试在本地保存日历数据以及使用 Google 服务器,但我运气不佳。 [GDataEntryCalendarEventencodeWithCoder:] 引发异常,似乎 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);
我收到的错误是 -[GDataEntryCalendarEventencodeWithCoder:]: 无法识别的选择器发送到实例 0x4d60b40
感谢您的帮助!
In a calendar app I'm writing, I'm trying to save the calendar data locally as well as using Googles servers, but I'm not having much luck. [GDataEntryCalendarEvent encodeWithCoder:] brings up an exception, it seems that GData doesn't do this. The code I'm using is -
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);
and the error I'm getting is -[GDataEntryCalendarEvent encodeWithCoder:]: unrecognized selector sent to instance 0x4d60b40
Thanks for any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于任何可使用 NSKeyedArchiver 归档的对象,其类需要符合 NSCoding 协议。
GDataEntryCalendarEvent
不符合它,因此您会收到此错误。您不能使用此方法来保存内容。要在本地保存
GDataEntryCalendarEvent
实例,请查看这个线程
提到了一种将其转换为可以在文件中写出的 XML 的方法。For any object to be archivable using
NSKeyedArchiver
, its class needs to conform to theNSCoding
protocol.GDataEntryCalendarEvent
doesn't conform to it so you are getting this error. You can't use this approach to save the content.To save an instance of
GDataEntryCalendarEvent
locally, look atthis thread
which mentions a way to convert it to an XML that can be written out in a file.