0 votes
15 views
What is instanceType in Objective-c?
in Technology by (189k points)

1 Answer

0 votes

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

by (189k points)

Related questions

0 votes
1 answer 13 views
13 views asked Nov 10, 2020 in Technology by JackTerrance (189k points)
0 votes
1 answer 10 views
10 views asked Nov 10, 2020 in Technology by JackTerrance (189k points)
0 votes
1 answer 9 views
9 views asked Nov 10, 2020 in Technology by JackTerrance (189k points)
0 votes
1 answer 16 views
16 views asked Nov 10, 2020 in Technology by JackTerrance (189k points)
0 votes
1 answer 12 views
12 views asked Nov 10, 2020 in Technology by JackTerrance (189k points)
0 votes
1 answer 10 views
10 views asked Nov 10, 2020 in Technology by JackTerrance (189k points)
0 votes
1 answer 13 views
13 views asked Nov 10, 2020 in Technology by JackTerrance (189k points)
0 votes
1 answer 15 views
15 views asked Nov 10, 2020 in Technology by JackTerrance (189k points)
0 votes
1 answer 11 views
11 views asked Nov 10, 2020 in Technology by JackTerrance (189k points)
0 votes
1 answer 12 views
12 views asked Nov 10, 2020 in Technology by JackTerrance (189k points)
0 votes
1 answer 14 views
0 votes
1 answer 14 views
0 votes
1 answer 11 views
11 views asked Nov 10, 2020 in Technology by JackTerrance (189k points)
0 votes
1 answer 13 views
0 votes
1 answer 16 views
16 views asked Nov 10, 2020 in Technology by JackTerrance (189k points)
0 votes
1 answer 19 views
19 views asked Nov 10, 2020 in Technology by JackTerrance (189k points)
0 votes
1 answer 10 views
0 votes
1 answer 12 views
12 views asked Nov 10, 2020 in Technology by JackTerrance (189k points)
0 votes
1 answer 10 views
0 votes
1 answer 9 views
9 views asked Nov 10, 2020 in Technology by JackTerrance (189k points)
...