What happens when you invok...
What happens when you invok...
In Objective-C, when you invoke a method on a nil
pointer, the runtime will simply ignore the message and return nil
. This behavior is known as "messaging nil
" and is a fundamental part of the Objective-C runtime.
Here's what happens when you invoke a method on a nil
pointer:
The method is not executed: The code inside the method will not be executed, and the method will return immediately.
No crash or exception: Messaging nil
will not cause a crash or raise an exception. The runtime simply ignores the message and continues execution.
Return value is nil
: If the method has a return value, it will return nil
(or 0
for primitive types like int
or float
).
Here's an example:
NSString *myString = nil;
NSString *result ...
senior
Gợi ý câu hỏi phỏng vấn
Chưa có bình luận nào