From 734cee5f085c2435b5954f044adb4d399b518c9a Mon Sep 17 00:00:00 2001 From: Gregg Jaskiewicz Date: Sat, 3 Feb 2018 18:26:05 +0000 Subject: [PATCH] update to swift 4 --- HostingApp/ViewController.swift | 6 +-- Keyboard/Catboard.swift | 10 ++--- Keyboard/CatboardBanner.swift | 2 +- Keyboard/DefaultSettings.swift | 2 +- Keyboard/KeyboardInputTraits.swift | 2 +- Keyboard/KeyboardKey.swift | 4 +- Keyboard/KeyboardViewController.swift | 44 +++++++++---------- .../project.pbxproj | 24 ++++++---- 8 files changed, 50 insertions(+), 44 deletions(-) diff --git a/HostingApp/ViewController.swift b/HostingApp/ViewController.swift index 1aeb8316..bc91166f 100644 --- a/HostingApp/ViewController.swift +++ b/HostingApp/ViewController.swift @@ -38,13 +38,13 @@ class HostingAppViewController: UIViewController { var secondHeightTime: TimeInterval? var referenceHeight: CGFloat = 216 - func keyboardWillShow() { + @objc func keyboardWillShow() { if startTime == nil { startTime = CACurrentMediaTime() } } - func keyboardDidHide() { + @objc func keyboardDidHide() { startTime = nil firstHeightTime = nil secondHeightTime = nil @@ -52,7 +52,7 @@ class HostingAppViewController: UIViewController { self.stats?.text = "(Waiting for keyboard...)" } - func keyboardDidChangeFrame(_ notification: Notification) { + @objc func keyboardDidChangeFrame(_ notification: Notification) { //let frameBegin: CGRect! = notification.userInfo?[UIKeyboardFrameBeginUserInfoKey]?.CGRectValue let frameEnd: CGRect! = (notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as AnyObject).cgRectValue diff --git a/Keyboard/Catboard.swift b/Keyboard/Catboard.swift index bfe9034e..ce9866f9 100644 --- a/Keyboard/Catboard.swift +++ b/Keyboard/Catboard.swift @@ -40,7 +40,7 @@ class Catboard: KeyboardViewController { if key.type == .character || key.type == .specialCharacter { if let context = textDocumentProxy.documentContextBeforeInput { - if context.characters.count < 2 { + if context.count < 2 { textDocumentProxy.insertText(keyOutput) return } @@ -99,11 +99,11 @@ class Catboard: KeyboardViewController { return CatboardBanner(globalColors: type(of: self).globalColors, darkMode: false, solidColorMode: self.solidColorMode()) } - func takeScreenshotDelay() { + @objc func takeScreenshotDelay() { Timer.scheduledTimer(timeInterval: 0.1, target: self, selector: #selector(Catboard.takeScreenshot), userInfo: nil, repeats: false) } - func takeScreenshot() { + @objc func takeScreenshot() { if !self.view.bounds.isEmpty { UIDevice.current.beginGeneratingDeviceOrientationNotifications() @@ -137,10 +137,10 @@ class Catboard: KeyboardViewController { func randomCat() -> String { let cats = "πŸ±πŸ˜ΊπŸ˜ΈπŸ˜ΉπŸ˜½πŸ˜»πŸ˜ΏπŸ˜ΎπŸ˜ΌπŸ™€" - let numCats = cats.characters.count + let numCats = cats.count let randomCat = arc4random() % UInt32(numCats) - let index = cats.characters.index(cats.startIndex, offsetBy: Int(randomCat)) + let index = cats.index(cats.startIndex, offsetBy: Int(randomCat)) let character = cats[index] return String(character) diff --git a/Keyboard/CatboardBanner.swift b/Keyboard/CatboardBanner.swift index f15ae9d1..fb3b969a 100644 --- a/Keyboard/CatboardBanner.swift +++ b/Keyboard/CatboardBanner.swift @@ -47,7 +47,7 @@ class CatboardBanner: ExtraView { self.catLabel.frame.origin = CGPoint(x: self.catSwitch.frame.origin.x + self.catSwitch.frame.width + 8, y: self.catLabel.frame.origin.y) } - func respondToSwitch() { + @objc func respondToSwitch() { UserDefaults.standard.set(self.catSwitch.isOn, forKey: kCatTypeEnabled) self.updateAppearance() } diff --git a/Keyboard/DefaultSettings.swift b/Keyboard/DefaultSettings.swift index 63592172..234680d5 100644 --- a/Keyboard/DefaultSettings.swift +++ b/Keyboard/DefaultSettings.swift @@ -183,7 +183,7 @@ class DefaultSettings: ExtraView, UITableViewDataSource, UITableViewDelegate { } } - func toggleSetting(_ sender: UISwitch) { + @objc func toggleSetting(_ sender: UISwitch) { if let cell = sender.superview as? UITableViewCell { if let indexPath = self.tableView?.indexPath(for: cell) { let key = self.settingsList[indexPath.section].1[indexPath.row] diff --git a/Keyboard/KeyboardInputTraits.swift b/Keyboard/KeyboardInputTraits.swift index 5b2ada50..da42f87a 100644 --- a/Keyboard/KeyboardInputTraits.swift +++ b/Keyboard/KeyboardInputTraits.swift @@ -28,7 +28,7 @@ extension KeyboardViewController { traitPollingTimer?.add(to: RunLoop.current, forMode: RunLoopMode.defaultRunLoopMode) } - func pollTraits() { + @objc func pollTraits() { let proxy = self.textDocumentProxy if let layout = self.layout { diff --git a/Keyboard/KeyboardKey.swift b/Keyboard/KeyboardKey.swift index 58ddffbe..eea5b405 100644 --- a/Keyboard/KeyboardKey.swift +++ b/Keyboard/KeyboardKey.swift @@ -425,7 +425,7 @@ class KeyboardKey: UIControl { } } - func showPopup() { + @objc func showPopup() { if self.popup == nil { self.layer.zPosition = 1000 @@ -450,7 +450,7 @@ class KeyboardKey: UIControl { } } - func hidePopup() { + @objc func hidePopup() { if self.popup != nil { self.delegate?.willHidePopup(for: self) diff --git a/Keyboard/KeyboardViewController.swift b/Keyboard/KeyboardViewController.swift index 45cbc687..ecfd25ec 100644 --- a/Keyboard/KeyboardViewController.swift +++ b/Keyboard/KeyboardViewController.swift @@ -125,7 +125,7 @@ class KeyboardViewController: UIInputViewController { NotificationCenter.default.removeObserver(self) } - func defaultsChanged(_ notification: Notification) { + @objc func defaultsChanged(_ notification: Notification) { //let defaults = notification.object as? NSUserDefaults self.updateKeyCaps(self.shiftState.uppercase()) } @@ -398,14 +398,14 @@ class KeyboardViewController: UIInputViewController { var keyWithDelayedPopup: KeyboardKey? var popupDelayTimer: Timer? - func showPopup(_ sender: KeyboardKey) { + @objc func showPopup(_ sender: KeyboardKey) { if sender == self.keyWithDelayedPopup { self.popupDelayTimer?.invalidate() } sender.showPopup() } - func hidePopupDelay(_ sender: KeyboardKey) { + @objc func hidePopupDelay(_ sender: KeyboardKey) { self.popupDelayTimer?.invalidate() if sender != self.keyWithDelayedPopup { @@ -418,7 +418,7 @@ class KeyboardViewController: UIInputViewController { } } - func hidePopupCallback() { + @objc func hidePopupCallback() { self.keyWithDelayedPopup?.hidePopup() self.keyWithDelayedPopup = nil self.popupDelayTimer = nil @@ -453,7 +453,7 @@ class KeyboardViewController: UIInputViewController { attribute:NSLayoutAttribute.notAnAttribute, multiplier:0, constant:height) - self.heightConstraint!.priority = 1000 + self.heightConstraint!.priority = UILayoutPriority(rawValue: 1000) self.view.addConstraint(self.heightConstraint!) // TODO: what if view already has constraint added? } @@ -471,15 +471,15 @@ class KeyboardViewController: UIInputViewController { self.settingsView?.darkMode = appearanceIsDark } - func highlightKey(_ sender: KeyboardKey) { + @objc func highlightKey(_ sender: KeyboardKey) { sender.isHighlighted = true } - func unHighlightKey(_ sender: KeyboardKey) { + @objc func unHighlightKey(_ sender: KeyboardKey) { sender.isHighlighted = false } - func keyPressedHelper(_ sender: KeyboardKey) { + @objc func keyPressedHelper(_ sender: KeyboardKey) { if let model = self.layout?.keyForView(sender) { self.keyPressed(model) @@ -566,7 +566,7 @@ class KeyboardViewController: UIInputViewController { self.backspaceRepeatTimer = nil } - func backspaceDown(_ sender: KeyboardKey) { + @objc func backspaceDown(_ sender: KeyboardKey) { self.cancelBackspaceTimers() self.textDocumentProxy.deleteBackward() @@ -576,23 +576,23 @@ class KeyboardViewController: UIInputViewController { self.backspaceDelayTimer = Timer.scheduledTimer(timeInterval: backspaceDelay - backspaceRepeat, target: self, selector: #selector(KeyboardViewController.backspaceDelayCallback), userInfo: nil, repeats: false) } - func backspaceUp(_ sender: KeyboardKey) { + @objc func backspaceUp(_ sender: KeyboardKey) { self.cancelBackspaceTimers() } - func backspaceDelayCallback() { + @objc func backspaceDelayCallback() { self.backspaceDelayTimer = nil self.backspaceRepeatTimer = Timer.scheduledTimer(timeInterval: backspaceRepeat, target: self, selector: #selector(KeyboardViewController.backspaceRepeatCallback), userInfo: nil, repeats: true) } - func backspaceRepeatCallback() { + @objc func backspaceRepeatCallback() { self.playKeySound() self.textDocumentProxy.deleteBackward() self.updateCapsIfNeeded() } - func shiftDown(_ sender: KeyboardKey) { + @objc func shiftDown(_ sender: KeyboardKey) { self.shiftStartingState = self.shiftState if let shiftStartingState = self.shiftStartingState { @@ -615,7 +615,7 @@ class KeyboardViewController: UIInputViewController { } } - func shiftUp(_ sender: KeyboardKey) { + @objc func shiftUp(_ sender: KeyboardKey) { if self.shiftWasMultitapped { // do nothing } @@ -643,7 +643,7 @@ class KeyboardViewController: UIInputViewController { self.shiftWasMultitapped = false } - func shiftDoubleTapped(_ sender: KeyboardKey) { + @objc func shiftDoubleTapped(_ sender: KeyboardKey) { self.shiftWasMultitapped = true switch self.shiftState { @@ -661,7 +661,7 @@ class KeyboardViewController: UIInputViewController { self.layout?.updateKeyCaps(false, uppercase: uppercase, characterUppercase: characterUppercase, shiftState: self.shiftState) } - func modeChangeTapped(_ sender: KeyboardKey) { + @objc func modeChangeTapped(_ sender: KeyboardKey) { if let toMode = self.layout?.viewToModel[sender]?.toMode { self.currentMode = toMode } @@ -679,7 +679,7 @@ class KeyboardViewController: UIInputViewController { self.setupKeys() } - func advanceTapped(_ sender: KeyboardKey) { + @objc func advanceTapped(_ sender: KeyboardKey) { self.forwardingView.resetTrackedViews() self.shiftStartingState = nil self.shiftWasMultitapped = false @@ -757,8 +757,8 @@ class KeyboardViewController: UIInputViewController { } func stringIsWhitespace(_ string: String?) -> Bool { - if string != nil { - for char in (string!).characters { + if let string = string { + for char in string { if !characterIsWhitespace(char) { return false } @@ -782,7 +782,7 @@ class KeyboardViewController: UIInputViewController { return false case .words: if let beforeContext = documentProxy.documentContextBeforeInput { - let previousCharacter = beforeContext[beforeContext.characters.index(before: beforeContext.endIndex)] + let previousCharacter = beforeContext[beforeContext.index(before: beforeContext.endIndex)] return self.characterIsWhitespace(previousCharacter) } else { @@ -791,7 +791,7 @@ class KeyboardViewController: UIInputViewController { case .sentences: if let beforeContext = documentProxy.documentContextBeforeInput { - let offset = min(3, beforeContext.characters.count) + let offset = min(3, beforeContext.count) var index = beforeContext.endIndex for i in 0 ..< offset { @@ -831,7 +831,7 @@ class KeyboardViewController: UIInputViewController { } // this only works if full access is enabled - func playKeySound() { + @objc func playKeySound() { if !UserDefaults.standard.bool(forKey: kKeyboardClicks) { return } diff --git a/TastyImitationKeyboard.xcodeproj/project.pbxproj b/TastyImitationKeyboard.xcodeproj/project.pbxproj index e7c78cf3..38f7bac5 100644 --- a/TastyImitationKeyboard.xcodeproj/project.pbxproj +++ b/TastyImitationKeyboard.xcodeproj/project.pbxproj @@ -393,15 +393,15 @@ TargetAttributes = { 4E807D9219461D9000D875D1 = { CreatedOnToolsVersion = 6.0; - LastSwiftMigration = 0810; + LastSwiftMigration = 0920; }; 4E807DB819461DC700D875D1 = { CreatedOnToolsVersion = 6.0; - LastSwiftMigration = 0810; + LastSwiftMigration = 0920; }; 4E8EF38019F95D74009CBF5D = { CreatedOnToolsVersion = 6.1; - LastSwiftMigration = 0810; + LastSwiftMigration = 0920; }; }; }; @@ -641,7 +641,8 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "Archagon.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -655,7 +656,8 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "Archagon.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.0; }; name = Release; }; @@ -668,7 +670,8 @@ PRODUCT_BUNDLE_IDENTIFIER = "Archagon.HostingApp.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = Keyboard; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -681,7 +684,8 @@ PRODUCT_BUNDLE_IDENTIFIER = "Archagon.HostingApp.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = Keyboard; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.0; }; name = Release; }; @@ -708,7 +712,8 @@ PRODUCT_BUNDLE_IDENTIFIER = "Archagon.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -733,7 +738,8 @@ PRODUCT_BUNDLE_IDENTIFIER = "Archagon.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = "";