From 9c946758bf15653b07166368c018b3735c51b67a Mon Sep 17 00:00:00 2001 From: Nate Weaver Date: Sun, 27 Oct 2019 11:38:41 -0500 Subject: [PATCH 1/2] Update Protocols and Delegates section --- Technotes/CodingGuidelines.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Technotes/CodingGuidelines.md b/Technotes/CodingGuidelines.md index a9014acf2..4795c1c01 100644 --- a/Technotes/CodingGuidelines.md +++ b/Technotes/CodingGuidelines.md @@ -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. +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. You’ll find several instances in the code, but this is done carefully — we don’t 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 what’s going on. There is one unfortunate case about protocols to note: in Swift you can’t 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. From 729b768547efb98dae0f47d26b3ccbf3efb8f012 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Mon, 28 Oct 2019 11:11:16 -0700 Subject: [PATCH 2/2] Update CodingGuidelines.md --- Technotes/CodingGuidelines.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Technotes/CodingGuidelines.md b/Technotes/CodingGuidelines.md index 4795c1c01..e7c11cdea 100644 --- a/Technotes/CodingGuidelines.md +++ b/Technotes/CodingGuidelines.md @@ -68,7 +68,7 @@ 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. +If a delegate protocol is 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. You’ll find several instances in the code, but this is done carefully — we don’t 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 what’s going on.