Skip to content

Commit 48d132e

Browse files
committed
Merge pull request kodecocodes#70 from gregheo/70-protocol-conformance
Protocol conformance in extensions
2 parents 9fdd164 + 8780758 commit 48d132e

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
* [Closure Expressions](#closure-expressions)
1920
* [Types](#types)
@@ -220,6 +221,33 @@ class BoardLocation {
220221
}
221222
```
222223

224+
### Protocol Conformance
225+
226+
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.
227+
228+
**Preferred:**
229+
```swift
230+
class MyViewcontroller: UIViewController {
231+
// class stuff here
232+
}
233+
234+
extension MyViewcontroller: UITableViewDataSource {
235+
// table view data source methods
236+
}
237+
238+
extension MyViewcontroller: UIScrollViewDelegate {
239+
// scroll view delegate methods
240+
}
241+
```
242+
243+
**Not Preferred:**
244+
```swift
245+
class MyViewcontroller: UIViewController, UITableViewDataSource, UIScrollViewDelegate {
246+
// all methods
247+
}
248+
```
249+
250+
223251
## Function Declarations
224252

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

0 commit comments

Comments
 (0)