devicekit / DeviceKit

DeviceKit is a value-type replacement of UIDevice.
MIT License
4.4k stars 425 forks source link

How Can I save the device to defaults? #350

Closed nessaNotFound closed 1 year ago

nessaNotFound commented 1 year ago

I have a fatal error when trying to set the device string as a key, print out is fine so I'm guessing I'm trying to store it as the wrong type(trying to store as a String) I've tried the Class of device and UIDevice.Device, but I thought I should just ask after some failed attempts?

The error: "Attempt to insert non-property list object Simulator (iPhone SE (3rd generation)) for key userDevice" the key:@AppStorage("userDevice") var userDevice: String = "" UserDefaults.standard.set(Device.current, forKey: "userDevice") print("--------------(userDevice)-----------")

(I want to save the users device info, and refrence it when loading the view to limit features depending on hardware capabilities. I'm a student so sorry in advance if this is a stupid issue to raise)

nessaNotFound commented 1 year ago

Device.current.description is the answer! Sorry figured it out.