ios – Observing changes in SwiftUI


I have the following property in my Settings class code:

 public var reducedFeatureMode:Bool {
    get {
        if let reducedFeatureMode = self.currentPreset.reducedFeatureMode {
            return reducedFeatureMode
        } else {
            return false
        }
    }
    
    set {
        var preset = self.currentPreset
        preset.reducedFeatureMode = newValue
        preset.save()
    }
 }

where currentPreset property is ultimately derived from UserDefaults OR a preconfigured Dictionary. TL;DR, there can be lot of code to fetch currentPreset. Now with SwiftUI code such as

 SettingsCell(.mic)
            .disabled(settings.reducedFeatureMode)

I want the SettingsCell to update automatically when settings.reducedFeatureMode changes. What do I need to do to make my Settings class observable?

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img