natashatherobot.com natashatherobot.com

Swift: Alternative to Default Implementations in Protocols

I recently wrote about why I prefer not to use default implementations in Swift protocols. TL;DR I want a lot of conscious thought put in into each method of the protocol – adding a default implementation will make it easy to forget and not think about much. Oh, and the compiler won’t complain! I want it to be easy to make changes in the implementation. If a method is not included in the file because the implementation is in the...

natashatherobot.com natashatherobot.com

Swift: Why You Shouldn’t Use Default Implementations in Protocols

I’m currently doing a very big refactor of try! Swift Data now that the Tokyo conference is over and I have time to repay some technical debt. As part of the refactor, I’m removing a bunch of large switch statements for view-level display data and putting them into individual view models that conform to a strict protocol. The Setup The conference app has different sessions – talks, breakfast, lunch, announcements, etc. They are...

natashatherobot.com natashatherobot.com

Implementing Equatable for Protocols in Swift

Last week I attended iOSDevCampDC, where I had the pleasure of hearing @ayanonagon‘s talk on testing. You can view the code sample here. For testing purposes and to my surprise, she implemented a default Equatable on a protocol similar to this: protocol Rectangle: Equatable { var width: Double { get } var height: Double { get} } // all objects that conform to this protocol // will now have default equality based on the...

natashatherobot.com natashatherobot.com

Protocol-Oriented Views in Swift

Join me for a Swift Community Celebration in New York City on September 1st and 2nd. Use code NATASHATHEROBOT to get $100 off! I recently gave a talk on Practical Protocol-Oriented-Programming(POP) in Swift. The video is still being processed. Meanwhile, here is the written-up version of the POP View part of the talk for reference (for me and anyone else!). The Setup Let’s say you have a simple app with an image an a button. The...