RawRepresentable using a NSKeyedArchiver
iOS 14 came with some exciting new features for SwiftUI and one of my favorites is the @AppStorage
wrapper. This new property wrapper makes storing a value in UserDefaults
way easier. Prior to iOS 14, this would have to be done by using getter and setter methods.
The @AppStorage natively supports Bool
, Int
, String
, URL
& Data
. But what if you want to display more complicated data types? For example, a SwiftUI Color
. I came across this problem myself developing one of my own apps. …
If your trying to display dynamic content in a single sheet on iOS 14 with SwiftUI you may have come across this problem.
In my case, I had multiple buttons launching different views inside of the same sheet using a state variable. You would click one button and an empty sheet would popup. Where the hell is my content? If you click a different button straight after, it works. But whatever button you click first will fail to display the correct content until a second button is clicked beforehand.
Really strange right? What makes it even more confusing is that…
Thanks to iOS 14 & SwiftUI, making Universal Apps has become even easier. Making Navigation look good on both iPad and iPhone can still be a bit tricky though. TabBars make sense on iPhone but on iPad they can look a bit out of place. One good alternative is using the new sidebar.
Defining the same set of views for navigating twice (Once for iPad and Once for iPhone) is not the cleanest way to achieve this though.
For one of my Apps I solved this by creating an AdaptiveNavigation
view.
Simple replace your root navigation view with an instance…
I make apps for the AppStore. Currently working on an app that makes gardening easier. Twitter: @iamzanecarter