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:

objc Copy
NSString *myString = nil;
NSString *result ...
senior

senior

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

middle

What is difference between these three classes [NSManagedObject, NSManagedObjectContext,
NSManagedObjectModel] of CoreData?

expert

What was wrong with the NSEnumerator technique and why NSFastEnumeration was introduced?

middle

When would you use Categories over Inheritance and vice versa?

Bình luận

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

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