2016-09-18 83 views
-1

1.为什么在XCode8NSKeyedArchiver.archivedData不能存档NSObject的(在Xcode 8 SWIFT)

2.错误消息

2016年9月17日21迅速运行程序时得到异常:59:56.370839 MyCalendar [1032:29793]子系统:com.apple.UIKit,类别:HIDEventFiltered,enable_level:0,persist_level:0,default_ttl:0,info_ttl:0,debug_ttl:0,generate_symptoms:0,enable_oversize:1, privacy_setting:2,enable_private_data:0 2016-09-17 21:59:56.371720 MyCalendar [1032:29793]子系统:com.apple.UIKit,category:HIDEvent Incoming,enable_level:0,persist_level:0,default_ttl:0,info_ttl:0,debug_ttl:0,generate_symptoms:0,enable_oversize:1,privacy_setting:2,enable_private_data:0 2016-09-17 21:59:56.390463 MyCalendar [ 1032:29782] subsystem:com.apple.BaseBoard,category:MachPort,enable_level:1,persist_level:0,default_ttl:0,info_ttl:0,debug_ttl:0,generate_symptoms:0,enable_oversize:0,privacy_setting:0,enable_private_data: 0 2016-09-17 21:59:56.412030 MyCalendar子系统:com.apple.UIKit,类别:StatusBar,enable_level:0,persist_level:0,default_ttl:0,info_ttl:0,debug_ttl:0, generate_symptoms:0,enable_oversize:1,privacy_setting:2,enable_private_data:0 2016-09-17 21:59:56.509619 MyCalendar [1032:29746]子系统:com.apple.BackBoardServices.fence,category:App,enable_level:1, persist_level:0,default_ttl:0,info_ttl:0,debug_ttl:0,generate_sympto ms:0,enable_oversize:0,privacy_setting:0,enable_private_data:0 2016-09-17 21:59:57.215510 MyCalendar [1032:29746]子系统:com.apple.UIKit,类别:Touch,enable_level:0,persist_level: 0,default_ttl:1,info_ttl:0,debug_ttl:0,generate_symptoms:0,enable_oversize:1,privacy_setting:2,enable_private_data:0 2016-09-17 21:59:57.216554 MyCalendar [1032:29746] subsystem:com。 apple.UIKit,类别:Gesture,enable_level:0,persist_level:0,default_ttl:1,info_ttl:0,debug_ttl:0,generate_symptoms:0,enable_oversize:1,privacy_setting:2,enable_private_data:0 2016-09-17 21 :59:57.218087 MyCalendar [1032:29746]子系统:com.apple.UIKit,类别:GestureEnvironment,enable_level:0,persist_level:0,default_ttl:1,info_ttl:0,debug_ttl:0,generate_symptoms:0,enable_oversize:1, privacy_setting:2,enable_private_data:0 2016-09-17 21 :59:57.218933 MyCalendar [1032:29746]子系统:com.apple.UIKit,类别:GestureExclusion,enable_level:0,persist_level:0,default_ttl:1,info_ttl:0,debug_ttl:0,generate_symptoms:0,enable_oversize:1, privacy_setting:2,enable_private_data:0 2-5 2016-09-17 22:00:00.519 MyCalendar [1032:29746] - [MyCalendar.CalendarEvent encodeWithCoder:]:无法识别的选择器发送到实例0x78e68120 2016-09-17 22 :00:00.547 MyCalendar [1032:29746] *终止应用程序由于未捕获的异常 'NSInvalidArgumentException',原因是: ' - [MyCalendar.CalendarEvent encodeWithCoder:]:无法识别的选择发送到实例0x78e68120' *第一掷调用堆栈: ( 0 CoreFoundation 0x00b95212 exceptionPreprocess + 1 94 1 libobjc.A。dylib 0x0064de66 objc_exception_throw + 52 2的CoreFoundation 0x00c0e3dc - [NSObject的(NSObject的)doesNotRecognizeSelector:] + 172 3的CoreFoundation 0x00b1434c ___forwarding_ + 1052 4的CoreFoundation 0x00b13f0e _CF_forwarding_prep_0 + 14 5基金会0x001ef60a _encodeObject + 1304 6基金会0x001ef0ea - [的NSKeyedArchiver encodeObject :forKey:] + 193 7基金会0x0022548a + [的NSKeyedArchiver archivedDataWithRootObject:] + 172 8 MyCalendar 0x000d47d2 _TFC10MyCalendar28SingleDayTableViewController16addButtonPressedfT6senderCSo15UIBarButtonItem_T_ + 1042 9 MyCalendar 0x000d4dad _TToFC10MyCalendar28SingleDayTableViewController16addButtonPressedfT6senderCSo15UIBar ButtonItem_T_ + 61 10 libobjc.A.dylib 0x00663200 - [NSObject的performSelector:withObject:withObject:] + 63 11的UIKit 0x00f9e81e - [UIApplication的sendAction:为:从:forEvent:] + 91 12的UIKit 0x01447f00 - [的UIBarButtonItem(UIInternal )_sendAction:withEvent:] + 186 13 libobjc.A.dylib 0x00663200 - [NSObject performSelector:withObject:withObject:] + 63 14 UIKit 0x00f9e81e - [UIApplication sendAction:to:from:forEvent:] + 91 15 UIKit 0x00f9e7b8 - [UIApplication的sendAction:toTarget:fromSender:forEvent:] + 41 16的UIKit 0x0114d32b - [UIControl sendAction:至:forEvent:] + 64 17的UIKit 0x0114d693 - [UIControl _sendActionsForEvents:withEvent:方法] + 462 18的UIKit 0x011 4d84a - [UIControl _sendActionsForEvents:withEvent:方法] + 901 19的UIKit 0x0114c518 - [UIControl touchesEnded:withEvent:方法] + 717 20的UIKit 0x01014fac - [一个UIWindow _sendTouchesForEvent:] + 3063 21的UIKit 0x010167e7 - [一个UIWindow的SendEvent:] + 4312 22 UIKit的0x00fbd198 - [UIApplication的的SendEvent:] + 395 23的UIKit 0x018646cd dispatchPreprocessedEventFromEventQueue + 3706 24的UIKit 0x0185c7af __handleEventQueue + 5345 25的CoreFoundation 0x00b34cbf __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 15 26的CoreFoundation 0x00b18df7 __CFRunLoopDoSources0 + 519 27的CoreFoundation 0x00b18284 __CFRunLoo PRUN + 1124 28的CoreFoundation 0x00b17bab CFRunLoopRunSpecific + 395个 29的CoreFoundation 0x00b17a0b CFRunLoopRunInMode + 123个 30个GraphicsServices 0x04dd1b4c GSEventRunModal + 177个 31 GraphicsServices 0x04dd19c7 GSEventRun + 80 32的UIKit 0x00f9c7fb UIApplicationMain + 148 33 MyCalendar 0x000d7431主+ 145 34 libdyld.dylib 0x03f69799启动+ 1 ) 的libC++ abi.dylib:与类型NSException的未捕获的异常终止

3.源代码

......

设CE = CalendarEvent(withTitle:newEvent,andDateString:defaultKey)

让encodedCE = NSKeyedArchiver.archivedData(withRootObject:CE)

..... 。

//类CalendarEvent 进口基金会

类CalendarEvent:NSObject的{VAR 标题:字符串 VAR dateString:字符串

init(withTitle t : String, andDateString ds : String) { 
    title = t 
    dateString = ds 
} 

init(withCoder coder : NSCoder) { 
    dateString = coder.decodeObject(forKey: "dateString") as! String 
    title = coder.decodeObject(forKey: "title") as! String 
} 

func encodeWithCoder(coder : NSCoder) { 
    coder.encode(dateString, forKey: "dateString") 
    coder.encode(title, forKey: "title") 
} 

}

4.与其他物体尝试

对于withRootObject,放置一个String(而不是CalendarEvents)时,一切正常。

回答