Skip to content

Instantly share code, notes, and snippets.

@fedejordan
Created February 24, 2018 18:36
Show Gist options
  • Save fedejordan/c1488c263561216e6763dd1c3b6021a0 to your computer and use it in GitHub Desktop.
Save fedejordan/c1488c263561216e6763dd1c3b6021a0 to your computer and use it in GitHub Desktop.
Blog03 - Testing Twitter API
import UIKit
import TwitterKit
class RetweetViewController: UIViewController {
@IBOutlet private weak var tweetIdTextField: UITextField!
@IBAction private func didSelectRetweet(sender: UIButton) {
guard let tweetId = tweetIdTextField.text else { return }
let client = TWTRAPIClient()
client.loadTweet(withID: tweetId) { (tweet, error) -> Void in
if let text = tweet?.text {
self.showAlert(withText: text)
} else {
self.showAlert(withText: "Data not found")
}
}
}
private func showAlert(withText text: String) {
let alert = UIAlertController(title: "Tweet example", message: text, preferredStyle: .alert)
let alertAction = UIAlertAction(title: "OK", style: .cancel, handler: nil)
alert.addAction(alertAction)
present(alert, animated: true, completion: nil)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment