Câu hỏi phỏng vấn Objective-C
Câu hỏi

What happens when you invok...

Câu trả lời

Invoking a Method on a Nil Pointer in Objective-C

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:

  1. The method is not executed: The code inside the method will not be executed, and the method will return immediately.

  2. No crash or exception: Messaging nil will not cause a crash or raise an exception. The runtime simply ignores the message and continues execution.

  3. 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

senior

Gợi ý câu hỏi phỏng vấn

middle

What is the difference between NSDictionary and NSMutableDictionary ?

middle

What is the difference between inheritance and Categories in Objective-C?

expert

Explain method swizzling. When you would use it?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào