Created
March 26, 2015 08:16
-
-
Save bitomule/b766b264e79bf77386c1 to your computer and use it in GitHub Desktop.
Swfit NSDictionary Extension with helpers to parse ObjectiveDDP dictionaries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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