I am having a problem in swift 4. In my controller I have a list and a segmented element that reload the list when it changes, and when I move fast throught the list and then select another segment the APP crash and return this backtrace:
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x20)
frame #0: 0x0000000180dce7e8 libobjc.A.dylib`object_isClass + 16
frame #1: 0x00000001825383e8 Foundation`KVO_IS_RETAINING_ALL_OBSERVERS_OF_THIS_OBJECT_IF_IT_CRASHES_AN_OBSERVER_WAS_OVERRELEASED_OR_SMASHED + 68
frame #2: 0x00000001825368ec Foundation`NSKeyValueWillChangeWithPerThreadPendingNotifications + 300
frame #3: 0x0000000185ba1614 QuartzCore`CAAnimation_setter(CAAnimation*, unsigned int, _CAValueType, void const*) + 156
frame #4: 0x0000000185ba11ec QuartzCore`-[CAAnimation setBeginTime:] + 32
frame #5: 0x0000000185b7e804 QuartzCore`CA::Layer::commit_animations(CA::Transaction*, double (*)(CA::Layer*, double, void*), void (*)(CA::Layer*, CA::Render::Animation*, void*), void (*)(CA::Layer*, __CFString const*, void*), void*) + 560
frame #6: 0x0000000185b7e2a8 QuartzCore`CA::Layer::commit_if_needed(CA::Transaction*, void (*)(CA::Layer*, unsigned int, unsigned int, void*), void*) + 416
frame #7: 0x0000000185b7e20c QuartzCore`CA::Layer::commit_if_needed(CA::Transaction*, void (*)(CA::Layer*, unsigned int, unsigned int, void*), void*) + 260
frame #8: 0x0000000185b7e20c QuartzCore`CA::Layer::commit_if_needed(CA::Transaction*, void (*)(CA::Layer*, unsigned int, unsigned int, void*), void*) + 260
frame #9: 0x0000000185b7e20c QuartzCore`CA::Layer::commit_if_needed(CA::Transaction*, void (*)(CA::Layer*, unsigned int, unsigned int, void*), void*) + 260
frame #10: 0x0000000185b7e20c QuartzCore`CA::Layer::commit_if_needed(CA::Transaction*, void (*)(CA::Layer*, unsigned int, unsigned int, void*), void*) + 260
frame #11: 0x0000000185b7e20c QuartzCore`CA::Layer::commit_if_needed(CA::Transaction*, void (*)(CA::Layer*, unsigned int, unsigned int, void*), void*) + 260
frame #12: 0x0000000185b7e20c QuartzCore`CA::Layer::commit_if_needed(CA::Transaction*, void (*)(CA::Layer*, unsigned int, unsigned int, void*), void*) + 260
frame #13: 0x0000000185b7e20c QuartzCore`CA::Layer::commit_if_needed(CA::Transaction*, void (*)(CA::Layer*, unsigned int, unsigned int, void*), void*) + 260
frame #14: 0x0000000185b7e20c QuartzCore`CA::Layer::commit_if_needed(CA::Transaction*, void (*)(CA::Layer*, unsigned int, unsigned int, void*), void*) + 260
frame #15: 0x0000000185b7e20c QuartzCore`CA::Layer::commit_if_needed(CA::Transaction*, void (*)(CA::Layer*, unsigned int, unsigned int, void*), void*) + 260
frame #16: 0x0000000185b7e20c QuartzCore`CA::Layer::commit_if_needed(CA::Transaction*, void (*)(CA::Layer*, unsigned int, unsigned int, void*), void*) + 260
frame #17: 0x0000000185b7e20c QuartzCore`CA::Layer::commit_if_needed(CA::Transaction*, void (*)(CA::Layer*, unsigned int, unsigned int, void*), void*) + 260
frame #18: 0x0000000185b7e20c QuartzCore`CA::Layer::commit_if_needed(CA::Transaction*, void (*)(CA::Layer*, unsigned int, unsigned int, void*), void*) + 260
frame #19: 0x0000000185ae31ac QuartzCore`CA::Context::commit_transaction(CA::Transaction*) + 2148
frame #20: 0x0000000185b08eb4 QuartzCore`CA::Transaction::commit() + 540
frame #21: 0x0000000185a5da04 QuartzCore`CA::Display::DisplayLink::dispatch_items(unsigned long long, unsigned long long, unsigned long long) + 928
frame #22: 0x0000000181dec1cc IOKit`IODispatchCalloutFromCFMessage + 392
frame #23: 0x0000000181b10010 CoreFoundation`__CFMachPortPerform + 188
frame #24: 0x0000000181b2a96c CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 56
frame #25: 0x0000000181b2a070 CoreFoundation`__CFRunLoopDoSource1 + 440
frame #26: 0x0000000181b27b44 CoreFoundation`__CFRunLoopRun + 2196
frame #27: 0x0000000181a47fb8 CoreFoundation`CFRunLoopRunSpecific + 436
frame #28: 0x00000001838dff84 GraphicsServices`GSEventRunModal + 100
frame #29: 0x000000018b01c2e8 UIKit`UIApplicationMain + 208
* frame #30: 0x00000001021b5d74 Pedidos`main at AppDelegate.swift:15
frame #31: 0x000000018156a56c libdyld.dylib`start + 4
I have seen in this post that it can be related with the observers, but I am not know how to define the observers declaration in that way. In my controller I have defined two observers for detect the keyboard
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
NotificationCenter.default.addObserver(self, selector: #selector(self.keyboardWillShow(notification:)), name: NSNotification.Name.UIKeyboardWillShow, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(self.keyboardWillHide(notification:)), name: NSNotification.Name.UIKeyboardWillHide, object: nil)
}
And on the viewWillDisappear
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIKeyboardWillShow, object: nil)
NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIKeyboardWillHide, object: nil)
}