Mixins and Traits in Swift 2.0

Great blog post with some really good specific examples of the benefits of using protocols and protocol extensions over inheritance when doing Swift development.

I had never heard the terms "Mixins" and "Traits" before reading this post, and they definitely seem like good words to add to the ol' vocabulary:

First off we have the interface. This is a protocol that just has method signatures but no actual code. This is what Objective-C and Swift 1.2 have.

A trait also has the actual method bodies. In other words, a trait adds code to an interface. This is the new thing that Swift 2.0 lets us do today with protocol extensions.

A mixin is like a trait but it also has state. We can’t really do this yet with Swift 2.0 as you’re not allowed to add stored properties to protocols.