parse.com - Back4app - Swift - Cast PFObject to Class -
i trying cast pfobject custom class in swift , read lot of post , in of need inherit class pfobject. problem class inherited nsobject , there conflict between then.
is there way cast pfobject custom class?
usuario.swift
class usuario: nsobject, nscoding { //mark: propriedades var nome: string? var foto: string? var datanascimento: date? var numerotelefone: string? var pais: paiscodigo? var telefonee164: string? var objectid: string? var created: date? var updated: date? override init() {} required init(coder adecoder: nscoder) { nome = adecoder.decodeobject(forkey: "nome") as? string foto = adecoder.decodeobject(forkey: "foto") as? string datanascimento = adecoder.decodeobject(forkey: "datanascimento") as? date numerotelefone = adecoder.decodeobject(forkey: "numerotelefone") as? string pais = adecoder.decodeobject(forkey: "pais") as? paiscodigo telefonee164 = adecoder.decodeobject(forkey: "telefonee164") as? string objectid = adecoder.decodeobject(forkey: "objectid") as? string created = adecoder.decodeobject(forkey: "created") as? date updated = adecoder.decodeobject(forkey: "updated") as? date } func encode(with acoder: nscoder) { if let nomeusuario = nome { acoder.encode(nomeusuario, forkey: "nome") } if let fotousuario = foto { acoder.encode(fotousuario, forkey: "foto") } if let datanascimentousuario = datanascimento { acoder.encode(datanascimentousuario, forkey: "datanascimento") } if let numerotelefoneusuario = numerotelefone { acoder.encode(numerotelefoneusuario, forkey: "numerotelefone") } if let paisusuario = pais { acoder.encode(paisusuario, forkey: "pais") } if let telefonee164usuario = telefonee164 { acoder.encode(telefonee164usuario, forkey: "telefonee164") } if let objectidusuario = objectid { acoder.encode(objectidusuario, forkey: "objectid") } if let createdusuario = created { acoder.encode(createdusuario, forkey: "created") } if let updatedusuario = updated { acoder.encode(updatedusuario, forkey: "updated") } } } the parse result using objectid returns me result:
<usuario: 0x6080000abb20, objectid: 7nwpmd81w3, localid: (null)> { nome = "pablo cavalcante"; numerotelefone = 67992497386; pais = "<paiscodigo: 0x6080000abb80, objectid: ra5wdiweft, localid: (null)>"; telefonee164 = "+5567992497386"; } so returns usuario object , need cast it.
you can use pfsubclassing. see you're declaring user class subclass pfuser , write this:
class user: pfuser, pfsubclassing { //mark: propriedades dynamic var nome: string? dynamic var foto: string? dynamic var datanascimento: date? dynamic var numerotelefone: string? dynamic var pais: paiscodigo? dynamic var telefonee164: string? dynamic var objectid: string? dynamic var created: date? dynamic var updated: date? } of course if you're using init(with:) , encode(with:) have implement it...
Comments
Post a Comment