Skip to content

Commit 8780758

Browse files
committed
Protocol conformance in extensions
1 parent 4232e52 commit 8780758

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

README.markdown

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Writing Objective-C? Check out our [Objective-C Style Guide](https://github.com/
1414
* [Comments](#comments)
1515
* [Classes and Structures](#classes-and-structures)
1616
* [Use of Self](#use-of-self)
17+
* [Protocol Conformance](#protocol-conformance)
1718
* [Function Declarations](#function-declarations)
1819
* [Closures](#closures)
1920
* [Types](#types)
@@ -210,6 +211,33 @@ class BoardLocation {
210211
}
211212
```
212213

214+
### Protocol Conformance
215+
216+
When adding protocol conformance to a class, prefer adding a separate class extension for the protocol methods. This keeps the related methods grouped together with the protocol and can simplify instructions to add a protocol to a class with its associated methods.
217+
218+
**Preferred:**
219+
```swift
220+
class MyViewcontroller: UIViewController {
221+
// class stuff here
222+
}
223+
224+
extension MyViewcontroller: UITableViewDataSource {
225+
// table view data source methods
226+
}
227+
228+
extension MyViewcontroller: UIScrollViewDelegate {
229+
// scroll view delegate methods
230+
}
231+
```
232+
233+
**Not Preferred:**
234+
```swift
235+
class MyViewcontroller: UIViewController, UITableViewDataSource, UIScrollViewDelegate {
236+
// all methods
237+
}
238+
```
239+
240+
213241
## Function Declarations
214242

215243
Keep short function declarations on one line including the opening brace:

0 commit comments

Comments
 (0)