2012-05-15 48 views
1

我使用下面的代碼NSArrayEKEvent轉換爲NSData和轉換NSDataunarchiveObjectWithDataNSArray。在轉換時,對象被更改並且它保存着值nullNSKeyedUnarchiver unarchiveObjectWithData皈依問題

爲什麼會顯示NULL。 (請參閱輸出)。任何人都知道解決方案讓我知道。提前致謝。

我編寫的代碼,

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

NSData *arrayData = [NSKeyedArchiver archivedDataWithRootObject:events]; 

NSArray *array = [NSKeyedUnarchiver unarchiveObjectWithData:arrayData]; 

輸出是

事件:( 「EKEvent < 0x4ad840> {EKEvent < 0x4ad840> {標題= 與日曆檢查;日曆= EKCalendar < 0x4bf2f0> {title = Calendar; type = Local; account =(null); allowsMo​​dify = YES; color = 0.443137 0.101961 0.462745 1.000000}; alarms =(\ 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);與會者=(空)} 「 )

陣列:( 」 EKEvent < 0x4c1e60> {EKEvent < 0x4c1e60> {標題=();日曆=(NULL);報警=(NULL); URL =( null); lastModified =(null)}; location =(null); startDate =(null); endDate =(null); allDay = 0; floating = 1; recurrence =(null); attendees =(null)}「 )

回答

0

雖然NSArray確認到NSCoding協議,EKEvent沒有。這是一個有點令人驚訝的是你沒有得到運行的代碼異常,類必須確認到NSCoding歸檔工作。

+0

感謝Per Johansson,我會嘗試使用NSCoding並讓你知道。 – mdhanifas

+1

我使用自定義類,並與NSCoding確認,但它不起作用。 它始終給出結果爲 ** EKEvent <0x46ba50> {EKEvent <0x46ba50> {title =(null);日曆=(空); alarm =(null); URL =(null); lastModified =(null)}; location =(null); startDate =(null); endDate =(null); allDay = 0; floating = 1; recurrence =(null);參加者=(null)} ** – mdhanifas

0

最後通過創建自定義EKEvent類並獲取每個值(如標題,startdate,enddate到NSCoding)來解決。然後它工作正常。

+0

您認爲您可以提供解決方案嗎?我遇到了這個問題......至少編碼部分:P – jsetting32