Skip to content

Instantly share code, notes, and snippets.

@niwatako
Created August 6, 2016 04:52
Show Gist options
  • Select an option

  • Save niwatako/e5a56f3ad62fd368995650756650005b to your computer and use it in GitHub Desktop.

Select an option

Save niwatako/e5a56f3ad62fd368995650756650005b to your computer and use it in GitHub Desktop.
TweetクラスにAPIのレスポンスからインスタンスを作るイニシャライザと、日付文字列をNSDate()に変換する機能を作る #CodePiece #realm_swift #realm_jp
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