Are id and instancetype same? If not, what are differences between them?
Answer / Lakhan Singh
In Objective-C, `id` is a generic type that can represent any object, while `instancetype` is a specific type defined by the class being initialized. The main difference is that `id` can represent any object, including objects of unknown or unrelated classes, whereas `instancetype` is always the same as the class being initialized. For example, if you create an instance of a custom class using `[[MyClass alloc] init]`, the return type is `MyClass *`, which is the same as `MyClass instancetype`. However, if you assign an instance of another class to an `id` variable, it will still be accepted but may result in runtime errors.
| Is This Answer Correct ? | 0 Yes | 0 No |
What is the difference between c and objective c?
Is swift or objective c better?
What is toll-free bridging?
What is a category extension?
What does the gc () method?
What is mark and sweep algorithm?
Can you please explain the way messaging works in objective-c?
What is the use of category in objective-c?
Explain the way messaging works in objective-c?
How to restart app in objective c?
What is protocol in networking?
Does a thread created using performselectorinbackground:withobject: creates its own autorelease pool?