Stephen A. Davis
webdavis.bsky.social
Stephen A. Davis
@webdavis.bsky.social
Hi, I’m Stephen 👋. I like to talk about software architecture and test-driven development 🧪

Check out my work on https://github.com/webdavis/webdavis
Now here's an enum *without* associated value types.

Since there are no associated value types the compiler says we can compare instances of this Error type and slaps on the Equatable protocol at compile time.
January 28, 2025 at 1:50 AM
As it turns out, in Swift, enums with no associated values get free Equatable synthesis!

Here is an enum *with* associated value types:
January 28, 2025 at 1:50 AM
We could explicitly conform RemoteFeedLoader.Error to Equatable like so, but apparently we don't need to? 🤔
January 28, 2025 at 1:50 AM
Here's the FeedLoader protocol's implementation class, RemoteFeedLoader.

No where in this code did we explicitly conform the Error type to Equatable:
January 28, 2025 at 1:50 AM
The puzzle 🧩:

Whenever I commented out the following line in the interface boundary, I would then get the accompanying compile-time error in the test code:
January 28, 2025 at 1:50 AM
😆 I won’t be passing any Ophthalmology tests, but I enjoyed the UI! Great work!
January 21, 2025 at 4:30 PM
(6/7)

Now let's see what it would be like to implement the same behavior without this syntax. We could convert this to a do-catch block, like so:
January 17, 2025 at 5:53 AM

(3/7)

Take a look at the following static function. Why isn't there a do-catch block to catch the potential error that JSONDecoder().decode throws?
January 17, 2025 at 5:53 AM
💻 Here's the Example Code:
January 15, 2025 at 8:42 AM
This is the Open/Closed Principle (OCP) in action! We don't have to change the view controller to extend it's behavior.

If we want to add more behavior to the view controller, then we just add another adapter that implements the delegate:
January 15, 2025 at 8:42 AM
Without it, a view controller's behavior would always be fixed, and Apple's framework wouldn't be very useful 😔
January 15, 2025 at 8:42 AM
Day 3 of #100DaysOfCode

Log: github.com/webdavis/100...

🧩 Delegates allow us to Extend the Behavior of a Client (1/5)

This is why UIKit.UITableView includes a DataSource/Delegate.

Here's the architecture:
January 15, 2025 at 8:42 AM