NSKeyedUnarchiver unarchiveObjectWithData转换问题

时间:2012-05-15 06:53:02

标签: ekevent

我使用以下代码将NSArray EKEvent转换为NSData,转换后的NSDataunarchiveObjectWithData转换为NSArray。转换时,对象会更改,并保留null值。

为什么会显示 NULL 。 (参考输出)。任何人都知道解决方案让我知道。在此先感谢。

我写的代码,

NSArray *events = [[self.eventStore eventsMatchingPredicate:predicate]retain];

NSData *arrayData = [NSKeyedArchiver archivedDataWithRootObject:events];

NSArray *array = [NSKeyedUnarchiver unarchiveObjectWithData:arrayData];

输出

  

事件:(       “EKEvent< 0x4ad840> {EKEvent< 0x4ad840> {title = 使用日历检查; calendar = EKCalendar< 0x4bf2f0> {title = Calendar; type = Local; account =(null); allowsMo​​dify =是;颜色= 0.443137 0.101961 0.462745 1.000000};报警=(\ n \“EKAlarm< 0x4be630> {triggerInterval = -300.000000} \”\ n); URL =(null); lastModified = 2012-05-14 12:15 :32 +0000}; location =(null); startDate = 2012-05-11 01:30:00 +0000; endDate = 2012-05-19 17:30:00 +0000; allDay = 0; floating = 0; recurrence =(null);参与者=(null)}“   )

  数组:(       “EKEvent< 0x4c1e60> {EKEvent< 0x4c1e60> {title =( null ); calendar =(null); alarms =(null); URL =(null); lastModified =(null)} ; location =(null); startDate =(null); endDate =(null); allDay = 0; floating = 1; recurrence =(null); attendees =(null)}“   )

2 个答案:

答案 0 :(得分:1)

最后通过创建自定义EKEvent类并将所有值(如title,startdate,enddate)添加到NSCoding来解决。然后它工作正常。

答案 1 :(得分:0)

虽然NSArray确认NSCoding协议,EKEvent却没有。有点令人惊讶的是,您没有运行代码的异常,该类必须确认NSCoding以便归档工作。

相关问题