Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Protocol conformance in extensions
  • Loading branch information
gregheo committed Dec 9, 2014
commit 87807581dc712c0d17063883e18bdeeeb2f9210a
28 changes: 28 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Writing Objective-C? Check out our [Objective-C Style Guide](https://github.com/
* [Comments](#comments)
* [Classes and Structures](#classes-and-structures)
* [Use of Self](#use-of-self)
* [Protocol Conformance](#protocol-conformance)
* [Function Declarations](#function-declarations)
* [Closures](#closures)
* [Types](#types)
Expand Down Expand Up @@ -210,6 +211,33 @@ class BoardLocation {
}
```

### Protocol Conformance

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.

**Preferred:**
```swift
class MyViewcontroller: UIViewController {
// class stuff here
}

extension MyViewcontroller: UITableViewDataSource {
// table view data source methods
}

extension MyViewcontroller: UIScrollViewDelegate {
// scroll view delegate methods
}
```

**Not Preferred:**
```swift
class MyViewcontroller: UIViewController, UITableViewDataSource, UIScrollViewDelegate {
// all methods
}
```


## Function Declarations

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