SwiftUI
Learn more and get better in building apps with SwiftUI.
Using NavigationLink programmatically based on binding in SwiftUI
NavigationLink in SwiftUI allows pushing a new destination view on a navigation controller. You can use NavigationLink in a list or decide to push a view programmatically. The latter enables you to trigger a new screen from a different location in your view. Allowing to push a new screen onto ...
Markdown rendering using Text in SwiftUI
SwiftUI comes with built-in markdown support for text, making it easy to transform the text into bold, italic, and other formats. iOS 15 and SwiftUI 3 introduced support taking away the need to combine text weight for similar results. Markdown isn't wholly supported (more on that later), but many features ...
Downloading and Caching images in SwiftUI
Downloading and caching images is an essential part of building apps in Swift. There are several ways of downloading images with 1st party APIs 3rd party libraries. In my experience, every developer has their way of handling remote images since there's no go-to standard. SwiftUI introduced AsyncImage as a 1st ...
Disable animations on a specific view in SwiftUI using transactions
Animations in SwiftUI look great and make your app shine, but sometimes you want to disable animations on a specific view since it doesn't look great when animating. Compared to UIKit, SwiftUI makes it easier to create animated transitions between two states using the animation view modifier. You can see ...
@Published risks and usage explained with code examples
@Published is one of the property wrappers in SwiftUI that allows us to trigger a view redraw whenever changes occur. You can use the wrapper combined with the ObservableObject protocol, but you can also use it within regular classes. It's essential to understand how the published property wrapper works since ...
@StateObject vs. @ObservedObject: The differences explained
The @StateObject and @ObservedObject property wrappers tell a SwiftUI view to update in response to changes from an observed object. Both wrappers look similar but have an essential distinction to be aware of when building apps in SwiftUI. At first, you might wonder why you wouldn't just always use @ObservedObject ...
How to use the Redacted View Modifier in SwiftUI with useful extensions
The redacted view modifier in SwiftUI allows us to create a so-called skeleton view while our data is loading. Using a skeleton view instead of a spinner lets the user get a sense of how our views will look once the data is loaded. The user experience is smoother and ...
@EnvironmentObject explained for sharing data between views in SwiftUI
@EnvironmentObject is part of the family of SwiftUI Property Wrappers that can make working with SwiftUI views a little easier. Sharing data between views can be challenging when working in SwiftUI, especially when we have a lot of child views being dependent on the same piece of data. We could ...
How to create a Conditional View Modifier in SwiftUI
Conditional View Modifier creation in SwiftUI allows you only to apply modifiers if a certain condition is true. Whether it's a simple checkbox value or an OS availability check, there are many cases in which you want to apply different configurations to your views. A View Modifier in SwiftUI modifies ...
How to create a Dynamic Pager View for onboardings
A pager view in SwiftUI like we know UIPageViewController in UIKit didn't exist until iOS 14 and macOS 11.0. Using the PageTabViewStyle on a TabView will result in a swipeable set of pages. However, what if you want to support iOS 13? And how would you do something similar on ...
withAnimation completion callback with animatable modifiers
SwiftUI is great when it comes down to animations as it does a lot for you with methods like withAnimation and animation(...). You can simply pass in the things you'd like it to animate and SwiftUI will make sure your views move smoothly from one state to another. Sometimes, however, ...
How to combine text weights in SwiftUI
Combining multiple text weights in SwiftUI might not look straight forward at first. If you're used to using UIKit you were probably looking into support for NSAttributedString in which you could apply different text styles for certain ranges. SwiftUI makes it possible to combine different text styles with the built-in ...