Trying to save a custom type using @SceneStorage. Here is what I did...please see sample code below
var rawValue: RawValue {
.... crashes ....
}
and **JSONEncoder.encode(self). seems to go recursive and crash into a EXCMEMACCESS, code: 2...
Any pointers are deeply appreciated !
made the custom type RawRepresentable conformant
marked it Codable
var rawValue: RawValue {
.... crashes ....
}
and **JSONEncoder.encode(self). seems to go recursive and crash into a EXCMEMACCESS, code: 2...
Any pointers are deeply appreciated !
Code Block swift struct AppUIState: RawRepresentable, Codable { typealias RawValue = String var enteredText: String? static let empty = """ { "enteredText": "" } """ init() { } init?(rawValue: RawValue) { guard let data = rawValue.data(using: .utf8), let result = try? JSONDecoder().decode(AppUIState.self, from: data) else { return nil } self = result } var rawValue: RawValue { debugPrint("var rawValue: self: \(self)") /* ===== 👇 exc mem access crash after .encode(self) executed... seems to go recursive ======*/ guard let data = try? JSONEncoder().encode(self), let stringResult = String(data: data, encoding: .utf8) else { return Self.empty } return stringResult } } /* View */ ContentView: View { @SceneStorage("SceneStorage.Keys.appUserState") var appUIState = AppUIState() ... ... ... ... } code-block