Skip to content

Instantly share code, notes, and snippets.

@bitomule
Created March 26, 2015 08:16
Show Gist options
  • Save bitomule/b766b264e79bf77386c1 to your computer and use it in GitHub Desktop.
Save bitomule/b766b264e79bf77386c1 to your computer and use it in GitHub Desktop.
Swfit NSDictionary Extension with helpers to parse ObjectiveDDP dictionaries
extension NSDictionary{
func getDateFromKey(key:String) -> NSNumber?{
if let date = (self.objectForKey(key) as? NSDictionary)?["$date"] as? NSNumber{
return date
}
return nil
}
func getFromKeyPath(keyPath:String)->AnyObject?{
let keysArray = split(keyPath) {$0 == "."}
if(keysArray.count > 0){
let newArray = Array(keysArray[1..<keysArray.count])
if let newDictionary = self.valueForKey(keysArray[0]) as? NSDictionary{
return newDictionary.getFromKeyPath(".".join(newArray))
}
}
return self.valueForKey(keyPath)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment