Matheo Fiebiger Agudelo2 min

Swiftly Highlights: Performance, SwiftData & TipKit

EngineeringNov 10, 2023

A new edition of Swiftly Highlights is here, grab your coffee and let’s talk about performance, SwiftUI and some shiny new topics.

Let's start with an interesting thought: Ever wondered which programming languages are used to develop our daily drivers, built-in apps? How many of these apps are written with Swift? What is the percentage of them using SwiftUI versus UIKit? How many binaries are in iOS 17 overall? Take a look at Apple’s use of Swift and SwiftUI in iOS 17 to get all the answers.

What’s New

SwiftData — a framework designed to help developers manage and interact with data on a persistent store; introduced in iOS 17 as a replacement for Core Data; the new kid on the block. You might be familiar with it already, but have you used it with SwiftUI Previews? Doing so will require some additional steps.

Concurrent programming in Core Data may not be difficult, but it’s full of traps. Even with ample experience in Core Data, even the slightest negligence can introduce vulnerabilities into the code, making the application unsafe. As the successor to Core Data, SwiftData provides a more elegant and secure mechanism for concurrent programming.

Now onto other topics. Managing the localization and translation of an app’s string resources can be a challenging task, but with XCode 15 and string catalogs, it has become much easier to localize iOS apps. This new localization tool has made life easier for developers.

Another new framework introduced at WWDC 2023, TipKit, allows you to easily display tips in your applications. It can be used to introduce new features to users, help them discover hidden options, or demonstrate faster ways to accomplish tasks, among other scenarios.

And definitely take a look at the new modifiers for SwiftUI; every year, SwiftUI improves and gets new modifiers that widen the framework’s capabilities.

Performance

Now getting into some runtime optimization work. There’s a sufficient number of ways to increase the speed of a project at runtime. Limiting dynamic dispatch in classes, limiting dynamic dispatch at methods, optimizing your protocols… these are some options you have at your disposal.

Optimizing SwiftUI performance is also very important. SwiftUI employs a diffing algorithm to update the UI efficiently. When the source of truth for your views — such as @State or @ObservableObject — changes, SwiftUI re-renders only the affected views. However, this process can be resource-intensive for complex view hierarchies. Mastering SwiftUI performance is a must.

Tips, Tools & Best Practices

Have you heard of multiline Strings? It’s time to let “\n” go and start using this neat feature, offered by Swift.

Want to capture your app state across app launches? Are you using User Defaults best practices for this? User Defaults are the go-to solution for Swift applications to store preferences that persist across launches of your app.

And finally, it’s time to understand the execution of Thread dispatching and Actors. Actors ensure your code is executed on a specific thread, like the main or a background thread. They help you synchronize access to mutable states and prevent data races. However, little warning: developers commonly misunderstand how actors dispatch to threads in non-async contexts.

That’s it for this edition of Swiftly Highlights! Hope it was a good read. See you next time.

Share this article



Sign up to our newsletter

Monthly updates, real stuff, our views. No BS.