From 7ff58d6a0fd11ac004b624938117b09c1122ecdb Mon Sep 17 00:00:00 2001 From: Andy Liang Date: Wed, 11 Jul 2018 11:56:52 -0400 Subject: [PATCH] Fix SwifterMacDemo --- Swifter.xcodeproj/project.pbxproj | 6 +++- SwifterDemoMac/Base.lproj/Main.storyboard | 27 ++++++++++------- SwifterDemoMac/Tweet.swift | 25 ++++++++++++++++ SwifterDemoMac/ViewController.swift | 36 ++++++++++------------- 4 files changed, 61 insertions(+), 33 deletions(-) create mode 100644 SwifterDemoMac/Tweet.swift diff --git a/Swifter.xcodeproj/project.pbxproj b/Swifter.xcodeproj/project.pbxproj index 7bf9d5e6..6acc6bd3 100644 --- a/Swifter.xcodeproj/project.pbxproj +++ b/Swifter.xcodeproj/project.pbxproj @@ -74,6 +74,7 @@ 8BF1D6861948BCC100E3AA64 /* SwifterAccountsClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8BF1D6841948BCC100E3AA64 /* SwifterAccountsClient.swift */; }; 8BF1D6881948C11E00E3AA64 /* SwifterCredential.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8BF1D6871948C11E00E3AA64 /* SwifterCredential.swift */; }; 8BF1D6891948C11E00E3AA64 /* SwifterCredential.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8BF1D6871948C11E00E3AA64 /* SwifterCredential.swift */; }; + A1246D3A20F65E7300E1676E /* Tweet.swift in Sources */ = {isa = PBXBuildFile; fileRef = A1246D3920F65E7300E1676E /* Tweet.swift */; }; A17A694F1C78336200063DFD /* Operator++.swift in Sources */ = {isa = PBXBuildFile; fileRef = A17A694D1C78333400063DFD /* Operator++.swift */; }; A17A69501C78336300063DFD /* Operator++.swift in Sources */ = {isa = PBXBuildFile; fileRef = A17A694D1C78333400063DFD /* Operator++.swift */; }; A1AA8B001D5C514E00CE7F17 /* SwifterError.swift in Sources */ = {isa = PBXBuildFile; fileRef = A1AA8AFE1D5C50AE00CE7F17 /* SwifterError.swift */; }; @@ -196,6 +197,7 @@ 8BF1D67E194889B900E3AA64 /* SwifterClientProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwifterClientProtocol.swift; sourceTree = ""; }; 8BF1D6841948BCC100E3AA64 /* SwifterAccountsClient.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwifterAccountsClient.swift; sourceTree = ""; }; 8BF1D6871948C11E00E3AA64 /* SwifterCredential.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwifterCredential.swift; sourceTree = ""; }; + A1246D3920F65E7300E1676E /* Tweet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Tweet.swift; sourceTree = ""; }; A17A694D1C78333400063DFD /* Operator++.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Operator++.swift"; sourceTree = ""; }; A1AA8AFE1D5C50AE00CE7F17 /* SwifterError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwifterError.swift; sourceTree = ""; }; A1AA8B021D5C59D200CE7F17 /* TweetCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TweetCell.swift; sourceTree = ""; }; @@ -282,6 +284,8 @@ children = ( 8B300C4F1944AECB00993175 /* AppDelegate.swift */, 8B300C4D1944AECB00993175 /* ViewController.swift */, + 8B300C531944AECB00993175 /* Main.storyboard */, + A1246D3920F65E7300E1676E /* Tweet.swift */, 8B300C491944AECB00993175 /* Supporting Files */, ); path = SwifterDemoMac; @@ -291,7 +295,6 @@ isa = PBXGroup; children = ( 8B300C511944AECB00993175 /* Images.xcassets */, - 8B300C531944AECB00993175 /* Main.storyboard */, 8B300C4A1944AECB00993175 /* Info.plist */, ); name = "Supporting Files"; @@ -628,6 +631,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + A1246D3A20F65E7300E1676E /* Tweet.swift in Sources */, 8B300C501944AECB00993175 /* AppDelegate.swift in Sources */, 8B300C4E1944AECB00993175 /* ViewController.swift in Sources */, ); diff --git a/SwifterDemoMac/Base.lproj/Main.storyboard b/SwifterDemoMac/Base.lproj/Main.storyboard index 3cb87ecf..74d0aa30 100644 --- a/SwifterDemoMac/Base.lproj/Main.storyboard +++ b/SwifterDemoMac/Base.lproj/Main.storyboard @@ -1,14 +1,16 @@ - - + + - + + + - + @@ -17,6 +19,9 @@ + + + @@ -47,7 +52,7 @@ - + @@ -66,6 +71,7 @@ + @@ -82,7 +88,7 @@ - + @@ -101,6 +107,7 @@ + @@ -124,13 +131,12 @@ - - - + diff --git a/SwifterDemoMac/Tweet.swift b/SwifterDemoMac/Tweet.swift new file mode 100644 index 00000000..957b5e70 --- /dev/null +++ b/SwifterDemoMac/Tweet.swift @@ -0,0 +1,25 @@ +// +// Tweet.swift +// SwifterDemoMac +// +// Created by Andy Liang on 2018-07-11. +// Copyright © 2018 Matt Donnelly. All rights reserved. +// + +import Cocoa + +class Tweet: NSObject { + + // the name of the poster + @objc dynamic let name: String + + // the text of the tweet + @objc dynamic let text: String + + init(name: String, text: String) { + self.name = name + self.text = text + super.init() + } + +} diff --git a/SwifterDemoMac/ViewController.swift b/SwifterDemoMac/ViewController.swift index 94bfeff8..4347bede 100644 --- a/SwifterDemoMac/ViewController.swift +++ b/SwifterDemoMac/ViewController.swift @@ -28,19 +28,20 @@ import Accounts import SwifterMac class ViewController: NSViewController { - + let useACAccount = false + @objc dynamic var tweets: [Tweet] = [] - + override func viewDidLoad() { super.viewDidLoad() - + let failureHandler: (Error) -> Void = { print($0.localizedDescription) } - + if useACAccount { let accountStore = ACAccountStore() let accountType = accountStore.accountType(withAccountTypeIdentifier: ACAccountTypeIdentifierTwitter) - + accountStore.requestAccessToAccounts(with: accountType, options: nil) { granted, error in guard granted else { print("There are no Twitter accounts configured. You can add or create a Twitter account in Settings.") @@ -57,30 +58,23 @@ class ViewController: NSViewController { swifter.getHomeTimeline(count: 20, success: { statuses in print(statuses) - }, failure: failureHandler) + }, failure: failureHandler) } } else { - let swifter = Swifter(consumerKey: "nLl1mNYc25avPPF4oIzMyQzft", - consumerSecret: "Qm3e5JTXDhbbLl44cq6WdK00tSUwa17tWlO8Bf70douE4dcJe2") - swifter.authorize(withCallback: URL(string: "swifter://success")!, success: { _, _ in + let swifter = Swifter(consumerKey: "nLl1mNYc25avPPF4oIzMyQzft", + consumerSecret: "Qm3e5JTXDhbbLl44cq6WdK00tSUwa17tWlO8Bf70douE4dcJe2") + let callbackUrl = URL(string: "swifter://success")! + swifter.authorize(withCallback: callbackUrl, success: { _, _ in swifter.getHomeTimeline(count: 100, success: { statuses in guard let tweets = statuses.array else { return } self.tweets = tweets.map { - let tweet = Tweet() - tweet.text = $0["text"].string! - tweet.name = $0["user"]["name"].string! - return tweet + return Tweet(name: $0["user"]["name"].string!, text: $0["text"].string!) } - }, failure: failureHandler) }, failure: failureHandler) + }, failure: failureHandler) } } - } -class Tweet: NSObject { - - var name: String! - var text: String! - -} + +