Swift Higher Order Functions

Here is what I like about Swift the most… it forces me to think in terms of what I can only describe as decoupled behavior. Behavior or implementation that doesn’t depend on any specific type. This can be clearly observed with higher order functions, protocol oriented programming or just Swift in general.

So what are they? Higher order functions are functions that take other functions as parameters. And even though the implementation of these functions can be, as any implementation, verbose and easily replicated, the advantage of using higher order functions is the fact that they promote a much succinct and easier to understand code by eliminating clutter. Some of these functions even have a default behavior (sort(_:) for example will sort elements in ascending order) which is very useful.

Continue reading “Swift Higher Order Functions”

Swift Higher Order Functions

Reusability With Swift Protocols

Aaaaaand I am back from the holidays… Christmas was great. I got a chance to spend time with my beautiful wife and two sons visiting “The German City” – Leavenworth. It was great to just chill for a bit… slay ride with kids was amazing. Seeing horses brought all my childhood memories back.

Anyway, I would like to kick off this year by spending a bit more time talking about Swift protocols. We’ve already covered it briefly here. Take a look if you are interested in what i cleverly titled as “Practical Protocol-Oriented Programming”. Even if you think you already know what protocols are, take a few minutes to read this article. There are some cool things I bet you didn’t know about.

Continue reading “Reusability With Swift Protocols”

Reusability With Swift Protocols

Practical Protocol-Oriented Swift

In the beginning Swift protocols felt a bit off when compared to protocols in Objective-C. The fact that I can easily declare an optional method in Objective-C with

is one of many examples. Even though there is a way to somewhat replicate that same behavior in Swift by prepending @objc in front of your protocol declaration, the entire idea of having @objc inside of your Swift class is somewhat weird to me personally. Not that there is anything wrong with it since Swift is using Objective-C runtime anyway.

Swift is a Protocol-Oriented programming language and until Swift 2.0 it was a bit unclear how that really played into a greater scheme of things. However, after the announcement of Swift 2.0 and the ability to extend protocols in Swift 2.0, it became much clearer.

Continue reading “Practical Protocol-Oriented Swift”

Practical Protocol-Oriented Swift