Created
November 9, 2015 10:50
-
-
Save odrobnik/3ecde0247717ef8f00eb to your computer and use it in GitHub Desktop.
I would like to have this be an abstract class.
This file contains hidden or 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
class Entity: NSObject | |
{ | |
var objectID: String? | |
var createdAt: NSDate? | |
var updatedAt: NSDate? | |
required override init() | |
{ | |
} | |
required init(dictionary: Dictionary<String, AnyObject>) | |
{ | |
if let objectID = dictionary["objectId"] as? String | |
{ | |
self.objectID = objectID | |
} | |
if let createdAt = dictionary["createdAt"] as? String | |
{ | |
self.createdAt = NSDate.dateFromJSONDateString(createdAt) | |
} | |
if let updatedAt = dictionary["updatedAt"] as? String | |
{ | |
self.updatedAt = NSDate.dateFromJSONDateString(updatedAt) | |
} | |
} | |
func dictionaryRepresentation() -> Dictionary<String, AnyObject> | |
{ | |
var dict = Dictionary<String,String>() | |
if let objectID = objectID | |
{ | |
dict["objectId"] = objectID | |
} | |
if let createdAt = createdAt | |
{ | |
dict["createdAt"] = createdAt.JSONDateString() | |
} | |
if let updatedAt = updatedAt | |
{ | |
dict["updatedAt"] = updatedAt.JSONDateString() | |
} | |
return dict | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment