Open CPiersigilli opened 7 years ago
I have this code for os x simple app, but it does not work:
import Cocoa struct GeoFolderData { var nomeCartella:String var nomeCommittente:String? var dataCreazioneCartella:NSDate var dataModificaCartella:NSDate var isActive:Bool } extension GeoFolderData: JSONDecodable { init(object: JSONObject) throws { let decoder = JSONDecoder(object: object) nomeCartella = try decoder.decode("Nome_Cartella") nomeCommittente = try decoder.decode("Nome_Committente") dataCreazioneCartella = try decoder.decode(key: "dataCreazioneCartella") dataModificaCartella = try decoder.decode(key: "dataModificaCartella") isActive = try decoder.decode("Is_Active") } } extension GeoFolderData: JSONEncodable { func toJSON() throws -> Any { return try JSONEncoder.create({ (encoder) -> Void in try encoder.encode(nomeCartella, key: "Nome_Cartella") try encoder.encode(nomeCommittente, key: "Nome_Committente") try encoder.encode(dataCreazioneCartella, key: "Data_Creazione_Cartella") try encoder.encode(dataModificaCartella, key: "Data_Modifica_Cartella") try encoder.encode(isActive, key: "Is_Active") }) } } extension JSONDecoder { public func decode(key: String) throws -> NSDate { return try decode(String, transformer: JSONTransformer<StringToNSDate, StringToNSDate>) } }
With these errors:
Is there anyone who can help me? Thank you.
Did you trying asking this question on stackoverflow.com?
No. Now, see JSON encoding and decoding with “matthewcheok/JSONCodable” on stackoverflow.com
JSON encoding and decoding with “matthewcheok/JSONCodable”
You don't seem to import JSONCodable.
JSONCodable
I have this code for os x simple app, but it does not work:
With these errors:
Is there anyone who can help me? Thank you.