Created
June 15, 2014 13:16
-
-
Save higepon/256a0e34576da3090b9a to your computer and use it in GitHub Desktop.
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 func createFromJson(roomObj: Dictionary<String, AnyObject>) -> Room! { | |
if let id = roomObj["id"]? as? Int { | |
if let name = roomObj["name"]? as? String { | |
if let userObj = roomObj["user"]? as? Dictionary<String, AnyObject> { | |
if let user = User.createGuestFromJson(userObj) { | |
if let messageCount = roomObj["message_count"]? as? Int { | |
if let isRemoved = roomObj["removed"]? as? Bool { | |
if let dateString = roomObj["created_at"]? as? String { | |
let formatter = NSDateFormatter() | |
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssz" | |
if let createdAt = formatter.dateFromString(dateString) { | |
return Room(id: String(id), name: name, user: user, messageCount: messageCount, isRemoved: isRemoved, createdAt: createdAt); | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment