I have received the following crash report but I do not understand the issue.Line 487 points to a check if the pickerView in the delegate is a particular variable.
I suspect the problem is in the call to ==
.
if pickerView == assignedTo
This isn't really what you mean. This forces a call to the ==
function and tries to evaluate equality between these two objects. If one of them is nil
that will crash.
pickerView
should never be nil
, but I've encountered cases where UIKit sends nil
for parameters that should never be nil
. (This especially can happen if there are any calls to UIKit methods on background threads. Be very careful about not doing that, but it can also happen due to UIKit bugs.)
assignedTo
can be nil
if the view hasn't loaded. In theory you should never get this call in that case, but again, it's possible in the presence of bugs, again most commonly due to calling UIKit methods off the main thread (any UIKit methods; it doesn't always have to be related to this particular picker view), but UIKit sometimes has bugs of its own.
In any case, you don't mean "is pickerView equal to assignedTo." You mean "is pickerView exactly the same thing as assignedTo." That's ===
:
if pickerView === assignedTo
===
does a pointer comparison, so even in the face of an invalid nil
it's safe.
Keep in mind that this is almost certainly related to a race condition. The fact that it doesn't easily reproduce when you run it in the debugger doesn't mean anything. It might happen once in 10k tries, only in Release, exclusively on iPhone 6. That's the nature of race conditions.