Created
August 6, 2016 04:52
-
-
Save niwatako/e5a56f3ad62fd368995650756650005b to your computer and use it in GitHub Desktop.
TweetクラスにAPIのレスポンスからインスタンスを作るイニシャライザと、日付文字列をNSDate()に変換する機能を作る #CodePiece #realm_swift #realm_jp
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
| static var dateFormatter: NSDateFormatter { | |
| let dateFormatter = NSDateFormatter() | |
| dateFormatter.locale = NSLocale(localeIdentifier: "en_US_POSIX") | |
| dateFormatter.dateFormat = "EEE MMM dd HH:mm:ss Z yyyy" | |
| return dateFormatter | |
| } | |
| convenience init(tweetDictionary: [String: AnyObject]) { | |
| self.init() | |
| let user = tweetDictionary["user"] as! [String: AnyObject] | |
| name = user["name"] as! String | |
| text = tweetDictionary["text"] as! String | |
| iconURL = user["profile_image_url_https"] as! String | |
| id = tweetDictionary["id_str"] as! String | |
| createdAt = Tweet.dateFormatter.dateFromString(tweetDictionary["created_at"] as! String)! | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment