Protocol Oriented Programming is Not Always the Answer

In Swift, protocol-oriented programming is in fashion. There’s a lot of Swift code out there that’s “protocol-oriented”, some open-source libraries even state it as a feature. I think protocols are heavily overused in Swift, and oftentimes the problem at hand can be solved in a much simpler way. In short: don’t be dogmatic about using (or avoiding) protocols.

Chris Eidhof references the WWDC 2015 talk Protocol-Oriented Programming in Swift as an example of a problem solved using protocols, and at the same time how we lose flexibility and add complexity.

Protocol oriented programming certainly has it place, yet…

let the problem drive the solution, not the other way around.

Protocol Oriented Programming is Not a Silver Bullet ~ @chriseidhof

Error Handling in Swift

Topics covered include the Swift ErrorProtocol; coding with result types; throwing, propagating and handling errors; and a brief look at error handling and asynchronous operations.

This tutorial is a great starting point if you are new to coding in Swift.

Error Handling in Swift : @abargh

Stateful Loops and Swift Sequence Functions

Given the question:

“I’ve come across a situation a number of times where I write code that has to try something one or more times using a repeat…while loop and the condition relies upon variables that should be declared within the scope of the loop.”

@ericasadun shows two examples using Swift sequence functions. To complete the discussion, Erica writes a function that:

“…creates a stateful repeat-while loop, which is more or less what I believe the writer was aiming for. It uses a Boolean test, hides the use of sequence(state:next:), and allows a trailing closure for the body of the loop.”

Stateful loops and using Swift sequence functions.

Facebook SDK for Swift (Beta)

@nlutsenko of the Facebook team:

“Earlier this year we provided a complete Swift implementation for Bolts that exposes many native Swift features, including proper generic types, support for value types, and native Swift error handling.”

Building on that idea, the Facebook SDK for Swift beta has been announced.

Continue reading