Here are 5 (new) tips you can start using today 🚀

Hi 👋

I received very positive feedback about my previous email where I shared 5 tips you could start using immediately. So how about we go for 5 more?

#01 – No more #selector() with UIButton

If you’re like me, you’re probably sad every time you have to use a piece of Objective-C legacy in your Swift code 😢

Fortunately, this is becoming less and less needed: since iOS 14, UIButton offers a new API to directly provide a closure instead of the old-fashioned #selector() 👌

(If you want to learn more on this, I made a video about it last year!)

#02 – Using print() in the body of a View

When we’re debugging code, a little print() can be very useful to let us better understand what’s going on 🐛

But if you’ve ever tried to use print() inside the body of a SwiftUI View, you might have noticed that it doesn’t seem to work.

As it turns it’s possible to use print() there, but there’s a trick to it!

#03 – Small extension, better readability

Sometimes it’s the most simple extensions that can have the strongest impact on the readability of our code.

Here’s a typical example: by using the method .clamped(), our code becomes much more readable than if we had used min(max()) 😌

#04 – Gotta Catch’ Em All! 🎶

It’s only fair that Sarun gets to be featured twice in this newsletter, given how many great tips he’s shared!

This time he’s reminding us of the (many) different syntaxes we can rely on when we need to handle the Error that a piece of our code has thrown 👌

#05 – Finding call sites in Xcode

Finally, I wanted to finish by this tip Antoine had shared two years ago, because I actually used no later than last week!

When you need to inspect all the call sites of a function or a property, you definitely want to use this Xcode feature called “Find Call Hierarchy”, it will save you so much time!

Bonus – My own 5 tips

2 years ago I had made a video titled: “5 tips to improve your Swift code”!

So if you’re up for even more tips, I’ve put a link to the video just below 🍿👇

That’s all for this email, thanks for reading it!

If you’ve enjoyed it, feel free to forward it
to your friends and colleagues 🙌

I wish you an amazing week!

❤️

Previous
Previous

3 mistakes to avoid with Optionals

Next
Next

Discover XCTUnwrap()