Update Protocols and Delegates section

This commit is contained in:
Nate Weaver 2019-10-27 11:38:41 -05:00
parent 596d3e1101
commit 9c946758bf
1 changed files with 4 additions and 0 deletions

View File

@ -66,6 +66,10 @@ Consider this a hard rule: all Swift classes must be marked as `final`, and all
Protocols and delegates (which are also protocol-conforming) are preferred. Protocols and delegates (which are also protocol-conforming) are preferred.
Protocol conformance should be implemented in Swift extensions.
If a delegate protocol defined in the same file as the delegator class or struct, the protocol interface should be specified before the delegator.
Default implementations in protocols are allowed but ever-so-slightly discouraged. Youll find several instances in the code, but this is done carefully — we dont want this to be just another form of inheritance, where you find that you have to bounce back-and-forth between files to figure out whats going on. Default implementations in protocols are allowed but ever-so-slightly discouraged. Youll find several instances in the code, but this is done carefully — we dont want this to be just another form of inheritance, where you find that you have to bounce back-and-forth between files to figure out whats going on.
There is one unfortunate case about protocols to note: in Swift you cant create a Set of some protocol-conforming objects, and we use sets frequently. In those situations another solution — such as a thin object with a delegate — might be better. There is one unfortunate case about protocols to note: in Swift you cant create a Set of some protocol-conforming objects, and we use sets frequently. In those situations another solution — such as a thin object with a delegate — might be better.