iPhone 版 GData 无法使用编码器

发布于 2024-11-18 00:06:23 字数 896 浏览 5 评论 0原文

在我正在编写的日历应用程序中,我尝试在本地保存日历数据以及使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

玩心态 2024-11-25 00:06:23

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

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

For any object to be archivable using NSKeyedArchiver, its class needs to conform to the NSCoding 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 at this thread which mentions a way to convert it to an XML that can be written out in a file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文