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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s