Skip to content

Commit

Permalink
Update iOS demo to use to the wrapper API
Browse files Browse the repository at this point in the history
  • Loading branch information
zachwolfe committed Jul 24, 2017
1 parent ccaff82 commit 90d9591
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
9 changes: 7 additions & 2 deletions Sources/WrapperObjectTweet.swift
Expand Up @@ -13,18 +13,23 @@ extension Swifter {
public let text: String
public let user: User
public let entities: Entities
public let id: UInt64
public let idStr: String
public let retweetedStatus: Tweet?

init(text: String, user: User, entities: Entities, retweetedStatus: Tweet? = nil) {
init(text: String, user: User, entities: Entities, id: UInt64, idStr: String, retweetedStatus: Tweet? = nil) {
self.text = text
self.user = user
self.entities = entities
self.id = id
self.idStr = idStr
self.retweetedStatus = retweetedStatus
}

enum CodingKeys: String, CodingKey {
case text, user, entities
case text, user, entities, id
case retweetedStatus = "retweeted_status"
case idStr = "id_str"
}
}
}
6 changes: 4 additions & 2 deletions Swifter.xcodeproj/project.pbxproj
Expand Up @@ -836,14 +836,15 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
DEVELOPMENT_TEAM = "";
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
INFOPLIST_FILE = SwifterDemoiOS/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
METAL_ENABLE_DEBUG_INFO = YES;
PRODUCT_BUNDLE_IDENTIFIER = "com.mattdonnelly.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_BUNDLE_IDENTIFIER = com.mattdonnelly.SwifterDemoiOS;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
Expand All @@ -855,10 +856,11 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = SwifterDemoiOS/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
METAL_ENABLE_DEBUG_INFO = NO;
PRODUCT_BUNDLE_IDENTIFIER = "com.mattdonnelly.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_BUNDLE_IDENTIFIER = com.mattdonnelly.SwifterDemoiOS;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
Expand Down
6 changes: 2 additions & 4 deletions SwifterDemoiOS/AuthViewController.swift
Expand Up @@ -81,16 +81,14 @@ class AuthViewController: UIViewController, SFSafariViewControllerDelegate {
let failureHandler: (Error) -> Void = { error in
self.alert(title: "Error", message: error.localizedDescription)
}
self.swifter.getHomeTimeline(count: 20, success: { json in
self.swifter.getWrapperHomeTimeline(count: 20, success: { tweets in
// Successfully fetched timeline, so lets create and push the table view

let tweetsViewController = self.storyboard!.instantiateViewController(withIdentifier: "TweetsViewController") as! TweetsViewController
guard let tweets = json.array else { return }
tweetsViewController.tweets = tweets
self.navigationController?.pushViewController(tweetsViewController, animated: true)

}, failure: failureHandler)

}, failure: failureHandler)
}

func alert(title: String, message: String) {
Expand Down
10 changes: 5 additions & 5 deletions SwifterDemoiOS/TweetsViewController.swift
Expand Up @@ -29,7 +29,7 @@ import SafariServices

class TweetsViewController: UITableViewController {

var tweets : [JSON] = []
var tweets : [Swifter.Tweet] = []
let reuseIdentifier: String = "reuseIdentifier"

override func viewDidLoad() {
Expand All @@ -49,16 +49,16 @@ class TweetsViewController: UITableViewController {

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: reuseIdentifier, for: indexPath)
cell.textLabel?.text = tweets[indexPath.row]["text"].string
cell.detailTextLabel?.text = "By \(tweets[indexPath.row]["user"]["name"].string!), @\(tweets[indexPath.row]["user"]["screen_name"].string!)"
cell.textLabel?.text = tweets[indexPath.row].text
cell.detailTextLabel?.text = "By \(tweets[indexPath.row].user.name), @\(tweets[indexPath.row].user.screenName)"
return cell
}

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
guard #available(iOS 9.0, *) else { return }
let screenName = tweets[indexPath.row]["user"]["screen_name"].string!
let id = tweets[indexPath.row]["id_str"].string!
let screenName = tweets[indexPath.row].user.screenName
let id = tweets[indexPath.row].idStr
let url = URL(string: "https://twitter.com/\(screenName)/status/\(id)")!
let safariView = SFSafariViewController(url: url)
self.present(safariView, animated: true, completion: nil)
Expand Down

0 comments on commit 90d9591

Please sign in to comment.