Hi I'm using this code to save into UserDefault some datas
If I try to run this code into PlayGround I get this error
Code Block import UIKit //GLOBAL STRUCT USER struct User: Codable{ var info: UserInfo? } //MARK:-USER INFO struct UserInfo: Codable{ var companyName: String? var companyAddress: String? var companyCity: String? var companyCap: String? var companyTelephone: String? var companyFax: String? var companyMobile: String? var companyWeb: String? var companyEmail: String? var companyVat: String? var companySDI: String? var companyPEC: String? var companyLogo: String? } struct LocalData{ static var userDatas: User?{ get{ guard let datas = UserDefaults.standard.data(forKey: #function) else { return User(info: UserInfo(companyName: "", companyAddress: "", companyCity: "", companyCap: "", companyTelephone: "", companyFax: "", companyMobile: "", companyWeb: "", companyEmail: "", companyVat: "", companySDI: "", companyPEC: "", companyLogo: "")) } do{ let myData = try JSONDecoder().decode(User.self, from: datas) return myData } catch{ print(error) } return User(info: UserInfo(companyName: "", companyAddress: "", companyCity: "", companyCap: "", companyTelephone: "", companyFax: "", companyMobile: "", companyWeb: "", companyEmail: "", companyVat: "", companySDI: "", companyPEC: "", companyLogo: "")) } set{ guard let mydatas = try? JSONEncoder().encode(newValue) else { return } print(mydatas) UserDefaults.standard.setValue(mydatas, forKey: #function) } } } LocalData.userDatas?.info?.companyAddress = "TEST" print(LocalData.userDatas?.info)
If I try to run this code into PlayGround I get this error
How can I solve this?error: Execution was interrupted, reason: EXCBADACCESS (code=1, address=0x38).
The process has been left at the point where it was interrupted, use "thread return -x" to return to the state before expression evaluation.