Skip to content

Commit

Permalink
Fix SwifterMacDemo
Browse files Browse the repository at this point in the history
  • Loading branch information
meteochu committed Jul 11, 2018
1 parent 0de02b9 commit 7ff58d6
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 33 deletions.
6 changes: 5 additions & 1 deletion Swifter.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -196,6 +197,7 @@
8BF1D67E194889B900E3AA64 /* SwifterClientProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwifterClientProtocol.swift; sourceTree = "<group>"; };
8BF1D6841948BCC100E3AA64 /* SwifterAccountsClient.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwifterAccountsClient.swift; sourceTree = "<group>"; };
8BF1D6871948C11E00E3AA64 /* SwifterCredential.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwifterCredential.swift; sourceTree = "<group>"; };
A1246D3920F65E7300E1676E /* Tweet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Tweet.swift; sourceTree = "<group>"; };
A17A694D1C78333400063DFD /* Operator++.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Operator++.swift"; sourceTree = "<group>"; };
A1AA8AFE1D5C50AE00CE7F17 /* SwifterError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwifterError.swift; sourceTree = "<group>"; };
A1AA8B021D5C59D200CE7F17 /* TweetCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TweetCell.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -282,6 +284,8 @@
children = (
8B300C4F1944AECB00993175 /* AppDelegate.swift */,
8B300C4D1944AECB00993175 /* ViewController.swift */,
8B300C531944AECB00993175 /* Main.storyboard */,
A1246D3920F65E7300E1676E /* Tweet.swift */,
8B300C491944AECB00993175 /* Supporting Files */,
);
path = SwifterDemoMac;
Expand All @@ -291,7 +295,6 @@
isa = PBXGroup;
children = (
8B300C511944AECB00993175 /* Images.xcassets */,
8B300C531944AECB00993175 /* Main.storyboard */,
8B300C4A1944AECB00993175 /* Info.plist */,
);
name = "Supporting Files";
Expand Down Expand Up @@ -628,6 +631,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
A1246D3A20F65E7300E1676E /* Tweet.swift in Sources */,
8B300C501944AECB00993175 /* AppDelegate.swift in Sources */,
8B300C4E1944AECB00993175 /* ViewController.swift in Sources */,
);
Expand Down
27 changes: 16 additions & 11 deletions SwifterDemoMac/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="10102" systemVersion="15E39d" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="14269.14" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="10102"/>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14269.14"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Window Controller-->
<scene sceneID="R2V-B0-nI4">
<objects>
<windowController id="B8D-0N-5wS" sceneMemberID="viewController">
<window key="window" title="Swifter Demo" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" releasedWhenClosed="NO" showsToolbarButton="NO" visibleAtLaunch="NO" animationBehavior="default" id="IQv-IB-iLA">
<window key="window" title="Swifter Demo" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" animationBehavior="default" id="IQv-IB-iLA">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="196" y="240" width="480" height="270"/>
Expand All @@ -17,6 +19,9 @@
<rect key="frame" x="14" y="22" width="480" height="270"/>
<autoresizingMask key="autoresizingMask"/>
</view>
<connections>
<outlet property="delegate" destination="B8D-0N-5wS" id="LwG-Pb-g1P"/>
</connections>
</window>
<connections>
<segue destination="XfG-lQ-9wD" kind="relationship" relationship="window.shadowedContentViewController" id="cq2-FE-JQM"/>
Expand Down Expand Up @@ -47,7 +52,7 @@
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
<color key="gridColor" name="gridColor" catalog="System" colorSpace="catalog"/>
<tableColumns>
<tableColumn identifier="" width="107" minWidth="10" maxWidth="3.4028234663852886e+38" id="LPE-S7-K3d">
<tableColumn width="107" minWidth="10" maxWidth="3.4028234663852886e+38" id="LPE-S7-K3d">
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" alignment="left" title="User">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
Expand All @@ -66,6 +71,7 @@
<subviews>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="R79-Nb-4Xd">
<rect key="frame" x="0.0" y="0.0" width="105" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" alignment="left" title="Table View Cell" id="Qmz-WN-XSG">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
Expand All @@ -82,7 +88,7 @@
</tableCellView>
</prototypeCellViews>
</tableColumn>
<tableColumn identifier="" width="630" minWidth="10" maxWidth="3.4028234663852886e+38" id="kkN-Nw-VVr">
<tableColumn width="630" minWidth="10" maxWidth="3.4028234663852886e+38" id="kkN-Nw-VVr">
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" alignment="left" title="Tweets">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
Expand All @@ -101,6 +107,7 @@
<subviews>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="mro-7b-YT6">
<rect key="frame" x="0.0" y="0.0" width="628" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" title="Table View Cell" id="rCm-Ig-uLH">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
Expand All @@ -124,13 +131,12 @@
</connections>
</tableView>
</subviews>
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
</clipView>
<scroller key="horizontalScroller" hidden="YES" verticalHuggingPriority="750" horizontal="YES" id="Deb-EI-Mw9">
<scroller key="horizontalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" horizontal="YES" id="Deb-EI-Mw9">
<rect key="frame" x="-100" y="-100" width="238" height="16"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
<scroller key="verticalScroller" hidden="YES" verticalHuggingPriority="750" horizontal="NO" id="YWi-wK-AET">
<scroller key="verticalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" horizontal="NO" id="YWi-wK-AET">
<rect key="frame" x="224" y="17" width="15" height="102"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
Expand All @@ -151,12 +157,11 @@
<customObject id="rPt-NT-nkU" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
<arrayController objectClassName="SwifterDemoMac.Tweet" id="LF8-NU-CaZ">
<connections>
<binding destination="XfG-lQ-9wD" name="contentArrayForMultipleSelection" keyPath="self" previousBinding="3R4-aA-73b" id="GBb-UD-BFj"/>
<binding destination="XfG-lQ-9wD" name="contentArray" keyPath="tweets" id="3R4-aA-73b"/>
</connections>
</arrayController>
</objects>
<point key="canvasLocation" x="159.5" y="687"/>
<point key="canvasLocation" x="1" y="765"/>
</scene>
<!--Application-->
<scene sceneID="JPo-4y-FX3">
Expand Down
25 changes: 25 additions & 0 deletions SwifterDemoMac/Tweet.swift
Original file line number Diff line number Diff line change
@@ -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()
}

}
36 changes: 15 additions & 21 deletions SwifterDemoMac/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand All @@ -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!

}


0 comments on commit 7ff58d6

Please sign in to comment.