Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update to swift 4 #120

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions HostingApp/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,21 @@ 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

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

Expand Down
10 changes: 5 additions & 5 deletions Keyboard/Catboard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Keyboard/CatboardBanner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
2 changes: 1 addition & 1 deletion Keyboard/DefaultSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion Keyboard/KeyboardInputTraits.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions Keyboard/KeyboardKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ class KeyboardKey: UIControl {
}
}

func showPopup() {
@objc func showPopup() {
if self.popup == nil {
self.layer.zPosition = 1000

Expand All @@ -450,7 +450,7 @@ class KeyboardKey: UIControl {
}
}

func hidePopup() {
@objc func hidePopup() {
if self.popup != nil {
self.delegate?.willHidePopup(for: self)

Expand Down
44 changes: 22 additions & 22 deletions Keyboard/KeyboardViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down Expand Up @@ -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 {
Expand All @@ -418,7 +418,7 @@ class KeyboardViewController: UIInputViewController {
}
}

func hidePopupCallback() {
@objc func hidePopupCallback() {
self.keyWithDelayedPopup?.hidePopup()
self.keyWithDelayedPopup = nil
self.popupDelayTimer = nil
Expand Down Expand Up @@ -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?
}
Expand All @@ -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)

Expand Down Expand Up @@ -566,7 +566,7 @@ class KeyboardViewController: UIInputViewController {
self.backspaceRepeatTimer = nil
}

func backspaceDown(_ sender: KeyboardKey) {
@objc func backspaceDown(_ sender: KeyboardKey) {
self.cancelBackspaceTimers()

self.textDocumentProxy.deleteBackward()
Expand All @@ -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 {
Expand All @@ -615,7 +615,7 @@ class KeyboardViewController: UIInputViewController {
}
}

func shiftUp(_ sender: KeyboardKey) {
@objc func shiftUp(_ sender: KeyboardKey) {
if self.shiftWasMultitapped {
// do nothing
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
Expand All @@ -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
Expand Down Expand Up @@ -757,8 +757,8 @@ class KeyboardViewController: UIInputViewController {
}

func stringIsWhitespace(_ string: String?) -> Bool {
if string != nil {
for char in (string!).characters {
if let string = string {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd probably use a guard here instead, or even change the method to only accept unwrapped strings.

for char in string {
if !characterIsWhitespace(char) {
return false
}
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down
24 changes: 15 additions & 9 deletions TastyImitationKeyboard.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
};
};
Expand Down Expand Up @@ -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;
};
Expand All @@ -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;
};
Expand All @@ -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;
};
Expand All @@ -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;
};
Expand All @@ -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 = "";
Expand All @@ -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 = "";
Expand Down