Hallo Community,
ich habe ein Problem bzgl. UserDefaults und UITouch bzw UIEvent Objekte.. wie es aussieht kann man nur eine Reihe von Objekten abspeichern. Darunter Strings, Ints, Bools etc... Wenn man Objekte anderer Art persistieren möchte, soll man ja laut Doku NSData verwenden und es entsprechend casten.
Ich habe zu UserDefaults eine Extensions geschrieben um genau UIEvent-Objekte abzuspeichern:
Alles anzeigen
Eine andere Klasse "Foil" hat so eine UIEvent Property die folgendermaßen aussieht:
Alles anzeigen
Allerdings schmiert die App jedes mal ab, wenn ich ein UIEvent Objekt hinterlege.. Und zwar genau an dieser Stelle:
Das selbe Spiel habe ich mit UIColor Objekten gespielt.. Da klappt es jedoch einwandfrei..
Hat wer eine Idee, woran das liegen könnte? Was habe ich vergessen?
Die Konsole spuckt mir folgendes aus:
Alles anzeigen
Ich danke im Voraus und schöne Grüße
Onur
ich habe ein Problem bzgl. UserDefaults und UITouch bzw UIEvent Objekte.. wie es aussieht kann man nur eine Reihe von Objekten abspeichern. Darunter Strings, Ints, Bools etc... Wenn man Objekte anderer Art persistieren möchte, soll man ja laut Doku NSData verwenden und es entsprechend casten.
Ich habe zu UserDefaults eine Extensions geschrieben um genau UIEvent-Objekte abzuspeichern:
Quellcode
- extension UserDefaults {
- // UIEvent
- func event(forKey defaultName: String) -> UIEvent? {
- var event: UIEvent?
- if let eventData = data(forKey: defaultName) {
- event = NSKeyedUnarchiver.unarchiveObject(with: eventData) as? UIEvent
- }
- return event
- }
- func setEvent(_ value: UIEvent?, forKey defaultName: String) {
- var eventData: NSData?
- if let event = value {
- eventData = NSKeyedArchiver.archivedData(withRootObject: event) as NSData?
- }
- set(eventData, forKey: defaultName)
- }
- }
Eine andere Klasse "Foil" hat so eine UIEvent Property die folgendermaßen aussieht:
Quellcode
Allerdings schmiert die App jedes mal ab, wenn ich ein UIEvent Objekt hinterlege.. Und zwar genau an dieser Stelle:
Das selbe Spiel habe ich mit UIColor Objekten gespielt.. Da klappt es jedoch einwandfrei..
Hat wer eine Idee, woran das liegen könnte? Was habe ich vergessen?
Die Konsole spuckt mir folgendes aus:
Quellcode
- 2017-08-09 16:50:47.911 LectureNotes[8444:9857872] Unbalanced calls to begin/end appearance transitions for <UINavigationController: 0x7f856601fe00>.
- 2017-08-09 16:50:56.332 LectureNotes[8444:9857872] -[UIEvent encodeWithCoder:]: unrecognized selector sent to instance 0x600000236060
- 2017-08-09 16:51:02.369 LectureNotes[8444:9857872] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIEvent encodeWithCoder:]: unrecognized selector sent to instance 0x600000236060'
- *** First throw call stack:
- (
- 0 CoreFoundation 0x0000000107c52b0b __exceptionPreprocess + 171
- 1 libobjc.A.dylib 0x00000001076b7141 objc_exception_throw + 48
- 2 CoreFoundation 0x0000000107cc2134 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
- 3 CoreFoundation 0x0000000107bd9840 ___forwarding___ + 1024
- 4 CoreFoundation 0x0000000107bd93b8 _CF_forwarding_prep_0 + 120
- 5 Foundation 0x00000001071f5b16 _encodeObject + 1224
- 6 Foundation 0x00000001072293fe +[NSKeyedArchiver archivedDataWithRootObject:] + 156
- 7 LectureNotes 0x0000000107056457 _TFE12LectureNotesCSo12UserDefaults8setEventfTGSqCSo7UIEvent_6forKeySS_T_ + 215
- 8 LectureNotes 0x00000001070565f7 _TToFE12LectureNotesCSo12UserDefaults8setEventfTGSqCSo7UIEvent_6forKeySS_T_ + 87
- 9 LectureNotes 0x0000000107050fed _TFC12LectureNotes4Foils5eventGSqCSo7UIEvent_ + 157
- 10 LectureNotes 0x000000010704e141 _TFC12LectureNotes26PresentationViewController11savetouchesfTGSqGVs3SetCSo7UITouch__4withGSqCSo7UIEvent__T_ + 481
- 11 LectureNotes 0x000000010704f613 _TTWC12LectureNotes26PresentationViewControllerS_12DrawDelegateS_FS1_11savetouchesfTGSqGVs3SetCSo7UITouch__4withGSqCSo7UIEvent__T_ + 99
- 12 LectureNotes 0x0000000107035d5d _TFC12LectureNotes8DrawView12touchesEndedfTGVs3SetCSo7UITouch_4withGSqCSo7UIEvent__T_ + 525
- 13 LectureNotes 0x0000000107035e36 _TToFC12LectureNotes8DrawView12touchesEndedfTGVs3SetCSo7UITouch_4withGSqCSo7UIEvent__T_ + 102
- 14 UIKit 0x00000001087ce7ea -[UIWindow _sendTouchesForEvent:] + 2707
- 15 UIKit 0x00000001087cff00 -[UIWindow sendEvent:] + 4114
- 16 UIKit 0x000000010877ca84 -[UIApplication sendEvent:] + 352
- 17 UIKit 0x0000000108f605d4 __dispatchPreprocessedEventFromEventQueue + 2926
- 18 UIKit 0x0000000108f58532 __handleEventQueue + 1122
- 19 CoreFoundation 0x0000000107bf8c01 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
- 20 CoreFoundation 0x0000000107bde0cf __CFRunLoopDoSources0 + 527
- 21 CoreFoundation 0x0000000107bdd5ff __CFRunLoopRun + 911
- 22 CoreFoundation 0x0000000107bdd016 CFRunLoopRunSpecific + 406
- 23 GraphicsServices 0x000000010d7efa24 GSEventRunModal + 62
- 24 UIKit 0x000000010875f134 UIApplicationMain + 159
- 25 LectureNotes 0x00000001070543d7 main + 55
- 26 libdyld.dylib 0x000000010bc9965d start + 1
- 27 ??? 0x0000000000000001 0x0 + 1
- )
- libc++abi.dylib: terminating with uncaught exception of type NSException
Ich danke im Voraus und schöne Grüße
Onur
![:)](http://osxentwicklerforum.de/wcf/images/smilies/smile.png)