From e66830c69a073d9f961e4776fd6a6ee626a5f6a7 Mon Sep 17 00:00:00 2001 From: Safx Date: Sun, 6 Jan 2019 23:47:04 +0900 Subject: [PATCH 1/3] update README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5d43d0b..a08fcb4 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ TypetalkKit is an unofficial web API client for Typetalk. The following code gets user's topics and prints these. ```swift -TypetalkAPI.sendRequest(GetTopics()) { result in +TypetalkAPI.sendRequest(GetTopics(spaceKey: spaceKey)) { result in switch result { case .Success(let ts): for i in ts { From 71cbc33f5dce889f73a22d16559e3aaac0ec9e7f Mon Sep 17 00:00:00 2001 From: Yuji MATSUMOTO Date: Mon, 24 Jun 2019 22:22:47 +0900 Subject: [PATCH 2/3] Update to Swift-5.0 --- Cartfile | 4 ++-- Cartfile.private | 4 ++-- Cartfile.resolved | 9 ++++---- Carthage/Checkouts/APIKit | 2 +- Carthage/Checkouts/Alamofire | 2 +- Carthage/Checkouts/OHHTTPStubs | 2 +- Carthage/Checkouts/Starscream | 2 +- TypetalkKit.xcodeproj/project.pbxproj | 33 ++++++++++++--------------- 8 files changed, 27 insertions(+), 31 deletions(-) diff --git a/Cartfile b/Cartfile index 37846d8..483d507 100644 --- a/Cartfile +++ b/Cartfile @@ -1,2 +1,2 @@ -github "ishkawa/APIKit" "release/4.1.0" -github "daltoniam/Starscream" >= 3.0.6 +github "ishkawa/APIKit" "5.0.0" +github "daltoniam/Starscream" >= 3.1.0 diff --git a/Cartfile.private b/Cartfile.private index 231a3bd..08255d0 100644 --- a/Cartfile.private +++ b/Cartfile.private @@ -1,2 +1,2 @@ -github "Alamofire/Alamofire" ~> 4.2.0 -github "AliSoftware/OHHTTPStubs" "5.2.3-swift3" +github "Alamofire/Alamofire" ~> 4.8.0 +github "AliSoftware/OHHTTPStubs" ~> 8.0.0 diff --git a/Cartfile.resolved b/Cartfile.resolved index 7e8a9f9..eb95048 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,5 +1,4 @@ -github "Alamofire/Alamofire" "4.8.0" -github "AliSoftware/OHHTTPStubs" "5.2.3-swift3" -github "antitypical/Result" "4.0.0" -github "daltoniam/Starscream" "3.0.6" -github "ishkawa/APIKit" "22f56c457b54888ddd7a0bed27b77d0ee3eb8b78" +github "Alamofire/Alamofire" "4.8.2" +github "AliSoftware/OHHTTPStubs" "8.0.0" +github "daltoniam/Starscream" "3.1.0" +github "ishkawa/APIKit" "5.0.0" diff --git a/Carthage/Checkouts/APIKit b/Carthage/Checkouts/APIKit index 22f56c4..862a8f8 160000 --- a/Carthage/Checkouts/APIKit +++ b/Carthage/Checkouts/APIKit @@ -1 +1 @@ -Subproject commit 22f56c457b54888ddd7a0bed27b77d0ee3eb8b78 +Subproject commit 862a8f80dd117693750c6ddaba2fe6a85b061a9a diff --git a/Carthage/Checkouts/Alamofire b/Carthage/Checkouts/Alamofire index 32573d0..75bba56 160000 --- a/Carthage/Checkouts/Alamofire +++ b/Carthage/Checkouts/Alamofire @@ -1 +1 @@ -Subproject commit 32573d05b91d8b7349ca31b4726e80212483f02a +Subproject commit 75bba56748359f297a83f620d45f72cf4ebee4e7 diff --git a/Carthage/Checkouts/OHHTTPStubs b/Carthage/Checkouts/OHHTTPStubs index 57fecea..a5f9693 160000 --- a/Carthage/Checkouts/OHHTTPStubs +++ b/Carthage/Checkouts/OHHTTPStubs @@ -1 +1 @@ -Subproject commit 57feceaabf333e72b2c637dfba6c13a7a5c49619 +Subproject commit a5f9693dbf7a98e91cd7b72fff02bdd291ac66e0 diff --git a/Carthage/Checkouts/Starscream b/Carthage/Checkouts/Starscream index ebdc260..9c03ef7 160000 --- a/Carthage/Checkouts/Starscream +++ b/Carthage/Checkouts/Starscream @@ -1 +1 @@ -Subproject commit ebdc260ea64e68f7569c62e8744b5cd15d3a49d6 +Subproject commit 9c03ef715d1bc9334b446c90df53586dd38cf849 diff --git a/TypetalkKit.xcodeproj/project.pbxproj b/TypetalkKit.xcodeproj/project.pbxproj index 5f6815e..e704df8 100644 --- a/TypetalkKit.xcodeproj/project.pbxproj +++ b/TypetalkKit.xcodeproj/project.pbxproj @@ -999,19 +999,19 @@ }; 8D9D18471A77D54200E3BCCF = { CreatedOnToolsVersion = 6.1.1; - LastSwiftMigration = 1010; + LastSwiftMigration = 1020; }; 8D9D18511A77D54200E3BCCF = { CreatedOnToolsVersion = 6.1.1; - LastSwiftMigration = 1010; + LastSwiftMigration = 1020; }; 8DBA516719C5B47300BD88A3 = { CreatedOnToolsVersion = 6.1; - LastSwiftMigration = 0900; + LastSwiftMigration = ""; }; 8DBA517219C5B47400BD88A3 = { CreatedOnToolsVersion = 6.1; - LastSwiftMigration = 0900; + LastSwiftMigration = 1010; }; }; }; @@ -1020,6 +1020,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, ); mainGroup = 8DBA515E19C5B47300BD88A3; @@ -1464,7 +1465,7 @@ MACOSX_DEPLOYMENT_TARGET = 10.11; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -1477,7 +1478,7 @@ MACOSX_DEPLOYMENT_TARGET = 10.11; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.2; }; name = Release; }; @@ -1506,7 +1507,7 @@ PRODUCT_NAME = TypetalkKit; SDKROOT = macosx; SKIP_INSTALL = YES; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -1532,7 +1533,7 @@ PRODUCT_NAME = TypetalkKit; SDKROOT = macosx; SKIP_INSTALL = YES; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = Release; }; @@ -1557,7 +1558,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -1578,7 +1579,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.blogspot.safx-dev.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = Release; }; @@ -1709,8 +1710,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.blogspot.safx-dev.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = TypetalkKit; SKIP_INSTALL = YES; - SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -1733,8 +1733,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.blogspot.safx-dev.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = TypetalkKit; SKIP_INSTALL = YES; - SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Release; }; @@ -1754,8 +1753,7 @@ LIBRARY_SEARCH_PATHS = "$(inherited)"; PRODUCT_BUNDLE_IDENTIFIER = "com.blogspot.safx-dev.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -1771,8 +1769,7 @@ LIBRARY_SEARCH_PATHS = "$(inherited)"; PRODUCT_BUNDLE_IDENTIFIER = "com.blogspot.safx-dev.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Release; }; From 3dc1d1673776973f75bbb7fd3ad9487f98f35c84 Mon Sep 17 00:00:00 2001 From: Yuji MATSUMOTO Date: Mon, 24 Jun 2019 23:31:39 +0900 Subject: [PATCH 3/3] update for Xcode-10.2.1 --- .../Example-OSX.xcodeproj/project.pbxproj | 5 ++- Example-OSX/Example-OSX/AppDelegate.swift | 10 ++--- .../Example-OSX/MessageViewController.swift | 8 ++-- .../Example-OSX/TopicViewController.swift | 4 +- .../Example-iOS.xcodeproj/project.pbxproj | 5 ++- Example-iOS/Example-iOS/AppDelegate.swift | 10 ++--- .../Example-iOS/DetailViewController.swift | 6 +-- .../Example-iOS/MasterViewController.swift | 39 ++++++++++++++++++- 8 files changed, 62 insertions(+), 25 deletions(-) diff --git a/Example-OSX/Example-OSX.xcodeproj/project.pbxproj b/Example-OSX/Example-OSX.xcodeproj/project.pbxproj index 183df01..432c424 100644 --- a/Example-OSX/Example-OSX.xcodeproj/project.pbxproj +++ b/Example-OSX/Example-OSX.xcodeproj/project.pbxproj @@ -131,6 +131,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, Base, ); @@ -314,7 +315,7 @@ MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_BUNDLE_IDENTIFIER = "com.blogspot.safx-dev.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "Example-OSX"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -332,7 +333,7 @@ MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_BUNDLE_IDENTIFIER = "com.blogspot.safx-dev.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "Example-OSX"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; }; name = Release; }; diff --git a/Example-OSX/Example-OSX/AppDelegate.swift b/Example-OSX/Example-OSX/AppDelegate.swift index a1a568a..9004f6c 100644 --- a/Example-OSX/Example-OSX/AppDelegate.swift +++ b/Example-OSX/Example-OSX/AppDelegate.swift @@ -16,10 +16,10 @@ class AppDelegate: NSObject, NSApplicationDelegate { override func awakeFromNib() { super.awakeFromNib() _ = TypetalkAPI.setDeveloperSettings( - clientId: "Your ClientID", - clientSecret: "Your SecretID", - scopes: [Scope.my, Scope.topicRead], // e.g. typetalkkit://auth/success - redirectURI: "Your custome scheme") + clientId: "Your_ClientID", + clientSecret: "Your_SecretID", + scopes: [Scope.my, Scope.topicRead], + redirectURI: "Your_custome_scheme") // e.g. typetalkkit://auth/success _ = TypetalkAPI.restoreTokenFromAccountStore() } @@ -32,7 +32,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { // MARK - handleURL - func handleGetURLEvent(_ event: NSAppleEventDescriptor?, replyEvent: NSAppleEventDescriptor?) { + @objc func handleGetURLEvent(_ event: NSAppleEventDescriptor?, replyEvent: NSAppleEventDescriptor?) { if let ev = event, let url_str = ev.forKeyword(AEKeyword(keyDirectObject))?.stringValue, let url = URL(string: url_str), TypetalkAPI.isRedirectURL(url) { diff --git a/Example-OSX/Example-OSX/MessageViewController.swift b/Example-OSX/Example-OSX/MessageViewController.swift index ac43b11..a994110 100644 --- a/Example-OSX/Example-OSX/MessageViewController.swift +++ b/Example-OSX/Example-OSX/MessageViewController.swift @@ -53,18 +53,18 @@ class MessageViewController: NSViewController, NSTableViewDelegate, NSTableViewD } func tableView(_ tableView: NSTableView, viewFor viewForTableColumn: NSTableColumn?, row: Int) -> NSView? { - let cell = tableView.make(withIdentifier: "MessageCell", owner: nil) as! MessageCell + let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "MessageCell"), owner: nil) as! MessageCell cell.model = messages!.posts[row] return cell } - func tableView(_ tableView: NSTableView, heightOfRow row: Int) -> CGFloat { + /*func tableView(_ tableView: NSTableView, heightOfRow row: Int) -> CGFloat { let font = NSFont(name: "Helvetica", size: 13)! - let attr: [String:AnyObject] = [NSFontAttributeName: font] + let attr: [String:AnyObject] = [NSAttributedString.Key.font.rawValue: font] let mes = messages!.posts[row].message let size = (mes as NSString).size(withAttributes: attr) return max(size.height + 32, 56) - } + }*/ } diff --git a/Example-OSX/Example-OSX/TopicViewController.swift b/Example-OSX/Example-OSX/TopicViewController.swift index 5d8f3a0..d562d80 100644 --- a/Example-OSX/Example-OSX/TopicViewController.swift +++ b/Example-OSX/Example-OSX/TopicViewController.swift @@ -117,7 +117,7 @@ class TopicViewController: NSViewController, NSTableViewDelegate, NSTableViewDat if topics.count <= sender.selectedRow { return } let topic = topics[sender.selectedRow] - let controller = self.parent?.childViewControllers[1] as! MessageViewController + let controller = self.parent?.children[1] as! MessageViewController controller.detailItem = topic } @@ -128,7 +128,7 @@ class TopicViewController: NSViewController, NSTableViewDelegate, NSTableViewDat } func tableView(_ tableView: NSTableView, viewFor viewForTableColumn: NSTableColumn?, row: Int) -> NSView? { - let cell = tableView.make(withIdentifier: "TopicCell", owner: nil) as! NSTableCellView + let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "TopicCell"), owner: nil) as! NSTableCellView cell.textField?.stringValue = topics[row].topic.name return cell } diff --git a/Example-iOS/Example-iOS.xcodeproj/project.pbxproj b/Example-iOS/Example-iOS.xcodeproj/project.pbxproj index 3cb998b..b22b1b0 100644 --- a/Example-iOS/Example-iOS.xcodeproj/project.pbxproj +++ b/Example-iOS/Example-iOS.xcodeproj/project.pbxproj @@ -136,6 +136,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, Base, ); @@ -330,7 +331,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.blogspot.safx-dev.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "Example-iOS"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -347,7 +348,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.blogspot.safx-dev.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "Example-iOS"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; }; name = Release; }; diff --git a/Example-iOS/Example-iOS/AppDelegate.swift b/Example-iOS/Example-iOS/AppDelegate.swift index 523311c..2cdda5f 100644 --- a/Example-iOS/Example-iOS/AppDelegate.swift +++ b/Example-iOS/Example-iOS/AppDelegate.swift @@ -15,7 +15,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele var window: UIWindow? - func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool { + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool { let splitViewController = self.window!.rootViewController as! UISplitViewController let navigationController = splitViewController.viewControllers[splitViewController.viewControllers.count-1] as! UINavigationController //navigationController.topViewController!.navigationItem.leftBarButtonItem = splitViewController.displayModeButtonItem() @@ -24,18 +24,18 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele _ = TypetalkAPI.setDeveloperSettings( clientId: "Your ClientID", clientSecret: "Your SecretID", - scopes: [Scope.my, Scope.topicRead], // e.g. typetalkkit://auth/success - redirectURI: "Your custome scheme") + scopes: [Scope.my, Scope.topicRead], + redirectURI: "Your custome scheme") // e.g. typetalkkit://auth/success _ = TypetalkAPI.restoreTokenFromAccountStore() return true } - func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool { + func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool { if TypetalkAPI.isRedirectURL(url) { if #available(iOS 9.0, *) { - if let sourceApplication = options[UIApplicationOpenURLOptionsKey.sourceApplication] as! String?, sourceApplication == "com.apple.mobilesafari" { + if let sourceApplication = options[UIApplication.OpenURLOptionsKey.sourceApplication] as! String?, sourceApplication == "com.apple.mobilesafari" { return TypetalkAPI.authorizationDone(URL: url) } } else { diff --git a/Example-iOS/Example-iOS/DetailViewController.swift b/Example-iOS/Example-iOS/DetailViewController.swift index bac49d7..3e97c6f 100644 --- a/Example-iOS/Example-iOS/DetailViewController.swift +++ b/Example-iOS/Example-iOS/DetailViewController.swift @@ -17,7 +17,7 @@ class DetailViewController: UITableViewController { super.viewDidLoad() tableView.estimatedRowHeight = 44 - tableView.rowHeight = UITableViewAutomaticDimension + tableView.rowHeight = UITableView.automaticDimension self.title = detailItem?.topic.name getMessages() @@ -28,7 +28,7 @@ class DetailViewController: UITableViewController { case .connected : print("connected") case .disconnected(let err) : print("disconnected: \(String(describing: err))") case .postMessage(let res) : - self.append(newPost: res.post!) + self.append(newPost: res.post) DispatchQueue.main.async { () -> Void in weakTableView?.reloadData() } @@ -44,7 +44,7 @@ class DetailViewController: UITableViewController { TypetalkAPI.send(GetMessages(topicId: topicid)) { result -> Void in switch result { case .success(let ms): - self.posts = ms.posts! + self.posts = ms.posts self.tableView.reloadData() case .failure(let error): print(error) diff --git a/Example-iOS/Example-iOS/MasterViewController.swift b/Example-iOS/Example-iOS/MasterViewController.swift index 3860980..a41c943 100644 --- a/Example-iOS/Example-iOS/MasterViewController.swift +++ b/Example-iOS/Example-iOS/MasterViewController.swift @@ -35,10 +35,45 @@ class MasterViewController: UITableViewController { fetchData() } - fileprivate func fetchData() { + func fetchData() { + fetchSpace() + } + + func fetchSpace() { + if TypetalkAPI.isSignedIn { + TypetalkAPI.send(GetSpaces()) { result in + switch result { + case .success(let ss): + guard let mySpace = ss.mySpaces.last else { return } + self.fetchTopic(spaceKey: mySpace.space.key) + case .failure(let error): + print(error) + _ = TypetalkAPI.requestRefreshToken { (err) -> Void in + if err == nil { + self.fetchData() + } else { + TypetalkAPI.authorize { (error) -> Void in + if (error == nil) { + self.fetchData() + } + } + } + } + } + } + } else { + TypetalkAPI.authorize { (error) -> Void in + if (error == nil) { + self.fetchData() + } + } + } + } + + fileprivate func fetchTopic(spaceKey: String) { if TypetalkAPI.isSignedIn { - TypetalkAPI.send(GetTopics()) { result in + TypetalkAPI.send(GetTopics(spaceKey: spaceKey)) { result in switch result { case .success(let ts): self.topics = ts.topics