How can I get the data type of a "null" nil attribute in swift 3?

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)
                }
            }
        }
    }
    
asked by Francisco Javier Saldivar 06.10.2017 в 17:16
source

1 answer

1

Good morning.

First I advise you to use basic types of Swift and try to use as little as possible objective-C objects as Dictionary<String, Any> for this use [String:Any]

Answering your question, you know what your type of object is Any since Any is also a type, only generic. Another thing is that Any may or may not cast another type as String , Bool etc using objAny as? String

Greetings!

    
answered by 16.10.2017 в 16:25