Using Swift, how can I tell the difference between boolean and integer value when loading data from plist?
My application needs to be able to read the plist file and know the data type, so I created a function to determine the type of the object:
func getTypeOfObject(object: AnyObject) -> String {
if object as? [String:AnyObject] != nil {
return "dict"
} else if object as? [AnyObject] != nil {
return "array"
} else if object as? Bool != nil {
return "bool"
} else if object as? Int != nil {
return "int"
} else if object as? String != nil {
return "string"
} else {
return ""
}
}
The problem is, if I call the function on a number, I get "bool". If I change the function to check the number first, I get "int" when I pass in a boolean.
This is because when I create a dict from data in a plist file, booleans gets an integer value (1 for true and 0 for false).
Is there a way to get around this?
+3
source to share