0
 func Deserialize(_ json:Dictionary<String, Any>)  {
        for (keyName, value) in json {
            if let type = self.value(forKey: keyName) as? String{
                print("El valor con la etiqueta es de tipo estring")
            }
            if self.responds(to: NSSelectorFromString(keyName)) && !keyName.contains("fecha") {
                if let newValue = value as?  NSString{
                  self.setValue(newValue, forKey: keyName)
                } else if let newValue = value as? Bool{
                    self.setValue(newValue, forKey: keyName)
                } else if let newValue = value as? Int{
                    self.setValue(newValue, forKey: keyName)
                } else if let newValue = value as? Double{
                    self.setValue(newValue, forKey: keyName)
                }
            }
        }
    }
1

1 respuesta 1

1

Buenos días.

Primero te aconsejo usar tipos básicos de Swift e intentar usar lo menos posible objetos de objective-C como Dictionary<String, Any> para esto usa [String:Any]

Respondiendo a tu duda, ya sabes cual es tu tipo de objeto Any ya que Any también es un tipo, solo que genérico. Otra cosa es que Any se pueda o no castear a otro tipo como String, Bool etc mediante objAny as? String

Un saludo!

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.