You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Codable single values that are not containers currently cannot be converted to json with JSONEncoder.
That would be helpful though, example use case: Persist a simple enum to UserDefaults.
Example code:
enumE: Int, Codable {
caseone
}
funcsaveCodableToUserDefaults<T: Codable>(_object: T, forKeykey: String) {
do {
// note that we could use either PropertyListEncoder or JSONEncoder, we decided for JSONEncoder - do never change, or old data will not be able to be read againletdata = tryJSONEncoder().encode(object)
UserDefaults.standard.set(data, forKey: key)
}
catch {
assertionFailure()
}
}
saveCodableToUserDefaults(E.one, forKey: "test") // assertionFailure
Additional Detail from JIRA
md5: 4ba04756c592207606907d54614a872f
duplicates:
Issue Description:
Codable single values that are not containers currently cannot be converted to json with
JSONEncoder
.That would be helpful though, example use case: Persist a simple enum to UserDefaults.
Example code:
Also see discussion:
https://forums.swift.org/t/top-level-t-self-encoded-as-number-json-fragment/11001
The text was updated successfully, but these errors were encountered: