Resources

Xcode: Navigating Through Your Project

Xcode can be a bit daunting at first when you’re starting out as an iOS developer. It’s a very complex and capable program, which means it can be hard to find what you’re looking for.

Thomas has some good tips for Xcode, including using landmarks (TODO:, MARK:, FIXME:), search, groups and callers—which all make it much easier to find what you’re looking for or what you need to come back to later.

Check it out!

Link
Best Practices

Thomas Hanning has a great overview of the use-cases for stored properties and computed properties here.

Essentially, stored properties allow you to perform actions as the property’s value is about to be set (using willSet {}) or after it has been set (using didSet {}). With computed properties, you can also calculate a new value on the fly without storing a default value.

Link
Best Practices

Thomas Hanning outlines how to use the new defer keyword in Swift in his blog post.

Essentially, the defer keyword executes its block before exiting the scope it is contained within. It’s a great tool to ensure you do any clean-up code required, even if an error is thrown.

It’s almost like a deinit() block for your own functions!

Check out his full post here: http://www.thomashanning.com/swift-2-0-defer/

Link
Best Practices, Resources

Little Bites of Cocoa is a blog I recently discovered that offers some truly great bite-sized snippets of knowledge via a newsletter. It’s a good way to keep on top of new best practices and bits of knowledge.

In the latest newsletter, a bunch of handy Swift tricks were featured, with my favourite being this one:

  
It’s helped me cut way down on the pyramid of doom! And what’s even better is you can even throw in a condition using the where keyword to the end of the chain. 😍 brilliance.

Check out the rest here: https://littlebitesofcocoa.com/175-more-swift-tricks

Link
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