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

Support Swift 4 #9

Merged
merged 2 commits into from
Nov 22, 2017
Merged
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 Keynode.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
TargetAttributes = {
C725789E1A38A2ED00F859BA = {
CreatedOnToolsVersion = 6.2;
LastSwiftMigration = 0800;
LastSwiftMigration = 0910;
};
C72578A91A38A2ED00F859BA = {
CreatedOnToolsVersion = 6.2;
Expand Down Expand Up @@ -348,7 +348,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -367,7 +367,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.kyoheiito.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand Down
4 changes: 3 additions & 1 deletion Keynode.xcodeproj/xcshareddata/xcschemes/Keynode.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0800"
LastUpgradeVersion = "0910"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -40,6 +40,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
Expand Down Expand Up @@ -69,6 +70,7 @@
buildConfiguration = "Dev01"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
51 changes: 27 additions & 24 deletions Keynode/Keynode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,29 @@ import UIKit
}

open class Keynode {
private static var connector: Connector? = {
let connector = Connector(instance: ())
connector.workingTextField = UITextField()

DispatchQueue.main.async {
connector.workingTextField?.becomeFirstResponder()
}

return connector
}()
@objc(KeynodeConnector)
open class Connector: NSObject {
fileprivate init(instance: Void) {
super.init()
let center = NotificationCenter.default
center.addObserver(self, selector: #selector(Connector.keyboardDidShow(_:)), name: .UIKeyboardDidShow, object: nil)
center.addObserver(self, selector: #selector(Connector.keyboardDidHide(_:)), name: .UIKeyboardDidHide, object: nil)
workingInstance = self
}
fileprivate var workingInstance: Connector?
fileprivate var workingTextField: UITextField? {
didSet {
if let textField = workingTextField {

textField.inputAccessoryView = UIView()
textField.inputView = UIView()

Expand All @@ -32,21 +48,7 @@ open class Keynode {
}
}
}

open override class func initialize() {
super.initialize()

if self.isEqual(Connector.self) {
let connector = Connector()
connector.workingInstance = connector
connector.workingTextField = UITextField()

DispatchQueue.main.async {
connector.workingTextField?.becomeFirstResponder()
}
}
}


deinit {
NotificationCenter.default.removeObserver(self)
}
Expand Down Expand Up @@ -77,6 +79,7 @@ open class Keynode {
open lazy var gestureOffset: CGFloat = self.defaultInsetBottom

public init(view: UIView? = nil) {
connector = nil // referencing of initialize for keyboard.
targetView = view
super.init()

Expand Down Expand Up @@ -371,7 +374,7 @@ private extension Keynode.Connector {

// MARK: - Action Methods
extension Keynode.Connector {
func panGestureAction(_ gesture: UIPanGestureRecognizer) {
@objc func panGestureAction(_ gesture: UIPanGestureRecognizer) {
guard let keyboard = firstResponder?.keyboard, let window = keyboard.window else {
return
}
Expand All @@ -398,20 +401,20 @@ extension Keynode.Connector: UIGestureRecognizerDelegate {

// MARK: - NSNotificationCenter Methods
extension Keynode.Connector {
func textDidBeginEditing(_ notification: Notification) {
@objc func textDidBeginEditing(_ notification: Notification) {
if let responder = notification.object as? UIResponder {
setResponder(responder)
}
}

func didBecomeFirstResponder(_ notification: Notification) {
@objc func didBecomeFirstResponder(_ notification: Notification) {
if let responder = (notification as NSNotification).userInfo?[UIResponderFirstResponderUserInfoKey] as? UIResponder
, !(responder is UITextView) && !(responder is UITextField) {
setResponder(responder)
}
}

func keyboardWillShow(_ notification: Notification) {
@objc func keyboardWillShow(_ notification: Notification) {
if checkWork(workingTextField) {
return
}
Expand All @@ -425,7 +428,7 @@ extension Keynode.Connector {
}
}

func keyboardDidShow(_ notification: Notification) {
@objc func keyboardDidShow(_ notification: Notification) {
if checkWork(workingTextField) {
return
}
Expand All @@ -445,7 +448,7 @@ extension Keynode.Connector {
}
}

func keyboardWillHide(_ notification: Notification) {
@objc func keyboardWillHide(_ notification: Notification) {
if checkWork(workingTextField) {
return
}
Expand All @@ -459,7 +462,7 @@ extension Keynode.Connector {
}
}

func keyboardDidHide(_ notification: Notification) {
@objc func keyboardDidHide(_ notification: Notification) {
workingInstance = nil
}
}
Expand All @@ -469,7 +472,7 @@ internal extension UIResponder {
return #selector(UIResponder.firstResponderNotification(_:))
}

func firstResponderNotification(_ sender: AnyObject?) {
@objc func firstResponderNotification(_ sender: AnyObject?) {
let userInfo = [UIResponderFirstResponderUserInfoKey: self]
NotificationCenter.default.post(name: Notification.Name(rawValue: UIResponderFirstResponderNotification), object: sender, userInfo: userInfo)
}
Expand Down
36 changes: 27 additions & 9 deletions KeynodeExample/KeynodeExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -218,16 +218,16 @@
attributes = {
LastSwiftMigration = 0700;
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0800;
LastUpgradeCheck = 0910;
ORGANIZATIONNAME = kyohei_ito;
TargetAttributes = {
C7A212241A3DAC040013D665 = {
CreatedOnToolsVersion = 6.2;
LastSwiftMigration = 0800;
LastSwiftMigration = 0910;
};
C7A2123B1A3DAC040013D665 = {
CreatedOnToolsVersion = 6.2;
LastSwiftMigration = 0800;
LastSwiftMigration = 0910;
TestTargetID = C7A212241A3DAC040013D665;
};
};
Expand Down Expand Up @@ -358,14 +358,20 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -397,7 +403,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.kyoheiito.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Enterprise;
};
Expand All @@ -409,7 +415,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.kyoheiito.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/KeynodeExample.app/KeynodeExample";
};
name = Enterprise;
Expand All @@ -422,14 +428,20 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -468,14 +480,20 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -508,7 +526,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.kyoheiito.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -521,7 +539,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.kyoheiito.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand All @@ -537,7 +555,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.kyoheiito.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/KeynodeExample.app/KeynodeExample";
};
name = Debug;
Expand All @@ -550,7 +568,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.kyoheiito.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/KeynodeExample.app/KeynodeExample";
};
name = Release;
Expand Down
2 changes: 1 addition & 1 deletion KeynodeExample/KeynodeExample/RespondButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class RespondButton: UIButton {
return toolbar
}()

func buttonAction(_ sender: AnyObject) {
@objc func buttonAction(_ sender: AnyObject) {
self.resignFirstResponder()
}

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func needNotificationForFirstResponder(from: AnyObject?)

## Caution
* Obtain the `inputAccessoryView` of `superview` and has been operating the keyboard, you might not work if the specification has been changed, but it will be addressed in the earliest possible stage.
* `iOS7.0` ~ `iOS10.0` is confirmed operation.
* `iOS7.0` ~ `iOS11.0` is confirmed operation.

## Acknowledgements

Expand Down