Khoa 🔥 Profile picture
AppStore App of the Day @PastePalApp 🏆 Also made @GetAlmighty @wwdctogether @ChatJoyAI @CodelimeHQ @ShipmunkApp @IndieGoodies

Mar 16, 2022, 6 tweets

Swift is a very typesafe and expressive language.

With newer features mean we can find new ways to write even more concise Swift code.

Below are 5 sweet techniques that you can use to supercharge your codebase #iosdev 💪🤩

💪 allSatisfy

Instead of using filter and count, you can use allSatisfy to check whether all element satisfies a given condition

💪 keyPath

Available since Swift 5.2, keyPath is a type that references a property, allowing us to write much cleaner code.

Given that it is a type, we can store keyPath, pass it around, and combine them.

💪 Tuple
We can use tuples to sort based on multiple properties.

A tuple of Comparable elements conforms to Comparable protocol, meaning that each element in 2 tuples is compared in order.

Here we want to show a list of payments, sorted by beneficiary name, then to date.

💪 Raw string

With raw string, quotes and backslash are not treated as terminators or escape characters.

All we have to do is to use surround our string with hash #

💪 Subscript

Subscript has been around since the beginning in Swift, allowing us to specify accessing with square brackets.

What's nifty, is that it allows multiple parameters, and we can even name external parameters.

Share this Scrolly Tale with your friends.

A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.

Keep scrolling