Skip to content

Instantly share code, notes, and snippets.

@odrobnik
Created November 9, 2015 10:50
Show Gist options
  • Save odrobnik/3ecde0247717ef8f00eb to your computer and use it in GitHub Desktop.
Save odrobnik/3ecde0247717ef8f00eb to your computer and use it in GitHub Desktop.
I would like to have this be an abstract class.
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