Is there a way to access Managed Preferences through UserDefaults in Swift?

I’d like to access the values in plist files in /Library/ManagedPreferences. I tried UserDefaults.standard.object(forKey: "com.custom.app.domain") but that did not work

My goal is to deploy settings that are set in an MDM and read those settings in my Swift macOS app. I’m new to macOS development and have been banging my head against the internet trying to figure out how to do this. Would really appreciate any help, thank you!
Post not yet marked as solved Up vote post of mchow Down vote post of mchow
543 views
  • I would like to know the answer for above question.

Add a Comment

Replies

I am also looking for this solution. Were you able to find a way?

Finally I have figured this out through UserDefaults.standard. Its bit tricky This is my code

if let userDefaultDict = UserDefaults.standard.dictionaryRepresentation() as? [String: Any]{

        guard let <<yourStrVariable>> = userDefaultDict[<<your Key for the value >>] as? String
        else{
            //Throw error
        }
               }
    else{
        //Throw Error
    }