Skip to content

Commit 070f54c

Browse files
committed
Merge pull request kodecocodes#39 from mattglover/master
Added 'Class Constructor Methods'
2 parents effaa1b + 6838c46 commit 070f54c

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Here are some of the documents from Apple that informed the style guide. If some
4242
* [Conditionals](#conditionals)
4343
* [Ternary Operator](#ternary-operator)
4444
* [Init Methods](#init-methods)
45+
* [Class Constructor Methods](#class-constructor-methods)
4546
* [CGRect Functions](#cgrect-functions)
4647
* [Golden Path](#golden-path)
4748
* [Error handling](#error-handling)
@@ -547,7 +548,7 @@ result = a > b ? x = c > d ? c : d : y;
547548

548549
## Init Methods
549550

550-
Init methods should follow the convention provided by Apple's generated code template. A return type of 'instancetype' should also be used instead of 'id'.
551+
Init methods should follow the convention provided by Apple's generated code template. A return type of 'instancetype' should also be used instead of 'id'.
551552

552553
```objc
553554
- (instancetype)init {
@@ -559,6 +560,18 @@ Init methods should follow the convention provided by Apple's generated code tem
559560
}
560561
```
561562

563+
See [Class Constructor Methods](#class-constructor-methods) for link to article on instancetype.
564+
565+
## Class Constructor Methods
566+
567+
Where class constructor methods are used, these should always return type of 'instancetype' and never 'id'. This ensures the compiler correctly infers the result type.
568+
569+
```objc
570+
@interface Airplane
571+
+ (instancetype)airplaneWithType:(RWAirplaneType)type;
572+
@end
573+
```
574+
562575
More information on instancetype can be found on [NSHipster.com](http://nshipster.com/instancetype/).
563576
564577
## CGRect Functions

0 commit comments

Comments
 (0)