开发者

GData for iPhone can't use encoder

In a calendar app I'm writing, I'm trying to save the calendar data locally as well as using Goo开发者_如何学Cgles 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!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜