Created
February 24, 2018 18:36
-
-
Save fedejordan/c1488c263561216e6763dd1c3b6021a0 to your computer and use it in GitHub Desktop.
Blog03 - Testing Twitter API
This file contains 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
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