in Technology by
What is instanceType in Objective-c?

1 Answer

0 votes
by

@interface A :

NSObject — (instancetype)init;

@end

@interface B : A

@end

The init method from A is inherited to B. However, in both classes the method has a different return type. In A the return type is A and in B the return type is B.

There is no other way to declare the return type for initializers correctly. Note that most programming languages with classes don’t even have return types for constructors, therefore they completely avoid the issue.

This is the reason why Obj-C needs instancetype but of course it can be used outside initializers, too.

Related questions

0 votes
    Are id and instanceType same? If not, what are differences between them in Objective-C?...
asked Nov 10, 2020 in Technology by JackTerrance
0 votes
    Can we use both swift (.swft) and objective c (.h .m) in same xcode project ?...
asked Mar 9, 2021 in Technology by JackTerrance
0 votes
    How do I call Objective-C code from Swift?...
asked Mar 9, 2021 in Technology by JackTerrance
0 votes
    Explain the difference between Swift vs Objective-C.?...
asked Nov 30, 2020 in Technology by JackTerrance
0 votes
    What are benefits of collections views in Objective-C?...
asked Nov 10, 2020 in Technology by JackTerrance
0 votes
    How we can layout subviews in a view in Objective-C?...
asked Nov 10, 2020 in Technology by JackTerrance
0 votes
    What are the size classes in Objective-c?...
asked Nov 10, 2020 in Technology by JackTerrance
0 votes
    Why create a custom view in Objective-C?...
asked Nov 10, 2020 in Technology by JackTerrance
0 votes
    What is bundle in Objective-c?...
asked Nov 10, 2020 in Technology by JackTerrance
0 votes
    Can we create Dynamic Classes in Objective C? If Yes, Explain how to create with a valid use case?...
asked Nov 10, 2020 in Technology by JackTerrance
0 votes
    What is posing in Objective C?...
asked Nov 10, 2020 in Technology by JackTerrance
0 votes
    What is the isa member in Objective-C?...
asked Nov 10, 2020 in Technology by JackTerrance
0 votes
    What is an extension in Objective-C?...
asked Nov 10, 2020 in Technology by JackTerrance
0 votes
    Is Objective C, a dynamic language? True/False, explain....
asked Nov 10, 2020 in Technology by JackTerrance
0 votes
    What is id in Objective-C?...
asked Nov 10, 2020 in Technology by JackTerrance
...