There are two situations in which this was used:
The protocol method itself is marked optional , so we donβt know whether this method implements the protocol.
We send a message to AnyObject. We can send any known message of the AnyObject class - it cancels the type checking, but then we still do not know whether this object implements this method.
So, this question mark means sending this message arbitrarily and safely. If it turns out that the recipient does not implement it, do not send a message or return zero. If the recipient executes it, send a message, but now we must wrap any result in Optional (since otherwise we could not return nil in the first case).
Behind the scenes, Objective-C respondsToSelector: called. Therefore, this template is only available if the receiver is exposed to Objective-C. This is mainly an Objective-C language function, expressed in abbreviated abbreviated form.
source share