Here are 5 tips you can start using today 😎

Hi 👋

It’s the beginning of a new week and I want to start it by sharing with you 5 tips that you can start using today!

#01 – Number Formatters for Social Features

If you ever work on an app with social features, there’s a good chance that you’ll need to display numbers with this format: 12,3K or 32M.

Turns out there’s no need to write any custom code to achieve this result, because iOS already contains a built-in formatter just for this:

#02 – Shorthand if-let syntax

Last year Swift introduced a new shorter syntax to unwrap optionals:

if let optional {
// …
}

What’s pretty great is that you can update your entire project quite easily, just by running a couple regular expressions!

#03 – Localized Accessibility Labels of Images

Apple has always put a strong emphasis on making accessibility as simple as possible to implement and this tip is a perfect example of it.

You don’t actually need to update your code to provide an accessibilityLabel() for a SwiftUI Image!

Instead you can simply add a new entry to your Localizable.strings file, with the name of the image as the key 👌

#04 – Multiple Cursors in Xcode

This is one of my personal favorite trick in Xcode!

By using the shortcut⌃ – Control + ⇧ - SHIFT + Click” you can create multiple cursors, and it’s so useful when you’re refactoring or writing boilerplate code!

#05 – Dealing with iPhone and iPad Layouts

When you work on an app that supports both the iPhone and the iPad, it’s quite common for the layout of the UI to be slightly differentdepending on the device.

It’s usually little things, like a font size or the width of a cell. But if we’re not carefully, we can easily end up with UI code that’s littered with ifstatements, just to deal with these small differences 😔

And that’s where this 5th tip comes into play! Because this problem can be elegantly solved just by introducing a simple helper function:

Bonus – Handling Optionals in Tests

To finish, I also wanted to share one of my personal tips with you!

If you need to deal with optional values in your tests, there’s a much better solution than just force unwrapping them: you can use the function XCTUnwrap() instead 👌

I’ll explain how it works and why it’s a better choice in the video below 👇

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

I wish you an amazing week!

❤️

Previous
Previous

How to write your first Unit Test

Next
Next

Only 15% of iOS developers get the right answer 😧