Best Practices

radex.io has an excellent explanation of when you should AND shouldn’t use ‘guard’ in Swift. 🙌

‘Guard’ has quickly become one of my favourite way to help simplify my code by getting rid of lots of pyramids of doom! If if if 🙅.

Example:

guard !array.isEmpty else { return }

replaces the need to do an if statement around the entire code block that relies on the array not being empty and just returns from the function as soon as it finds an empty array without executing any further code in the function! 🎉

Make sure to check it out and try guard out in your code!

http://radex.io/swift/guard/

Link
Best Practices

Mixins over Inheritance – Crunchy Development

When coming from an Object-Oriented Programming language like ObjC, inheritance is often used to share code between multiple classes. But that solution is not always the best, and have some issues.

In today’s article, we’ll see how Swift’s Protocol Extensions and their usage as “Mixins” can change the deal.

via Mixins over Inheritance – Crunchy Development.

Check this amazing post out! Some really epic examples to show the power of Mixins (protocol extensions). ❤ it.

Standard
Best Practices

Using UIColor Better in Your App

An excellent post from Thoughtbot about how to make better use of Color in terms of design use (limiting your app to using 3 colours max), naming conventions (i.e. to base names on usage scenario instead of the actual colour, and use aliases), and programming techniques (how to use extensions and global functions with Colors). Some great ideas I’m going to use!

https://robots.thoughtbot.com/naming-colors

Standard