前置き
あるときから、こんな感じのエラー報告が度々上がるようになっていました。
再現性もほぼ100%で、どうもnavigationControllerのinteractivePopGestureRecognizerが実行されるときに発生しているようでしたが、直し方がわかりませんでした。
Crashed: com.apple.main-thread
EXC_BAD_ACCESS KERN_INVALID_ADDRESS at 0x216fd19d
0 libobjc.A.dylib objc_msgSend + 5 hash
1 CoreFoundation -[__NSSetM member:] + 68
2 CoreFoundation -[NSSet containsObject:] + 24
3 UIKit -[UIGestureRecognizer _shouldBegin] + 832
4 UIKit -[UIGestureRecognizer setState:] + 390
5 UIKit -[_UIScreenEdgePanRecognizer _incorporateIncrementalSampleAtLocation:timestamp:modifier:interfaceOrientation:] + 134
6 UIKit -[_UIScreenEdgePanRecognizer incorporateTouchSampleAtLocation:timestamp:modifier:interfaceOrientation:] + 138
7 UIKit -[UIScreenEdgePanGestureRecognizer touchesMoved:withEvent:] + 216
8 UIKit -[UIWindow _sendGesturesForEvent:] + 460
9 UIKit -[UIWindow sendEvent:] + 524
10 UIKit -[UIApplication sendEvent:] + 196
11 UIKit _UIApplicationHandleEventFromQueueEvent + 14414
12 UIKit _UIApplicationHandleEventQueue + 1352
原因
わかってしまえば単純なことで、interactivePopGestureRecognizer.delegateにviewDidLoadでselfを指定していたことが原因でした。
この機能について解説してあるブログを読んだときに、viewDidLoadで指定していたので何か理由があると思ってそのまま採用してしまった…。
やはりちゃんと考えないといけませんね。
self.navigationController.interactivePopGestureRecognizer.delegate = (id <UIGestureRecognizerDelegate>) self;
というわけで、この記述はviewWillAppear:などに記述しましょう。
また、必要ない画面では逆にnilを指定することを忘れずに。
そうしないと、EdgeGestureが実行されたときに最後にdelegateへ指定したViewControllerを参照しようとして、存在しないviewControllerを参照してcrashしてしまいます。