I suspect the problem is calling == .
if pickerView == assignedTo
This does not mean what you mean. This calls the == function call and tries to evaluate the equality between the two objects. If one of them is nil , that will work.
pickerView should never be nil , but I have seen cases where UIKit sends nil for parameters that should never be nil . (This can especially happen if there are any calls to UIKit methods in background threads. Be very careful not to do this, but it can also happen due to UIKit errors.)
assignedTo may be nil if the view is not loaded. Theoretically, you should never get this call in this case, but again, this is possible if there are errors, most often due to calling UIKit methods from the main thread (any UIKit methods that do not always have to be associated with this particular kind of choice) , but UIKit sometimes has its own mistakes.
In any case, you do not mean that "this is a pickerView equal to that assigned." You mean "this pickerView is exactly as intended." This === :
if pickerView === assignedTo
=== compares the pointer, so even in the case of an invalid nil it is safe.
Keep in mind that this is almost certainly related to race conditions. The fact that it is not easily reproduced when you run it in the debugger does not mean anything. This can happen once in 10k attempts, only in Release, exclusively on iPhone 6. This is the nature of the race conditions.
Rob napier
source share