Are id and instancetype same? If not, what are differences between them?
Answer Posted / 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 |
Post New Answer View All Answers
No New Questions to Answer in this Category !! You can
Post New Questions
Answer Questions in Different Category