Saving a Codable Struct to UserDefaults with Swift
问题 I am trying to encode a struct struct Configuration : Encodable, Decodable { private enum CodingKeys : String, CodingKey { case title = "title" case contents = "contents" } var title : String? var contents: [[Int]]? } into JSON to store in a local key of UserDefaults.standard. I have the following code: let jsonString = Configuration(title: nameField.text, contents: newContents) let info = ["row" as String: jsonString as Configuration] print("jsonString = \(jsonString)") //trying to save