diff --git a/.jazzy.yml b/.jazzy.yml index ae3032c..465c756 100644 --- a/.jazzy.yml +++ b/.jazzy.yml @@ -3,8 +3,8 @@ author: polydice author_url: https://github.com/polydice github_url: https://github.com/polydice/ICInputAccessory github_file_prefix: https://github.com/polydice/ICInputAccessory/blob/develop -xcodebuild_arguments: [-scheme, ICInputAccessory-iOS] +xcodebuild_arguments: [-project, ICInputAccessory.xcodeproj, -scheme, ICInputAccessory-iOS] module: ICInputAccessory -module_version: 1.2.1 +module_version: 1.3.0 output: docs/output theme: fullwidth diff --git a/.swift-version b/.swift-version new file mode 100644 index 0000000..4a36342 --- /dev/null +++ b/.swift-version @@ -0,0 +1 @@ +3.0.0 diff --git a/.swiftlint-version b/.swiftlint-version new file mode 100644 index 0000000..2a0970c --- /dev/null +++ b/.swiftlint-version @@ -0,0 +1 @@ +0.16.1 diff --git a/.swiftlint.yml b/.swiftlint.yml index a180bf9..a9a6baa 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -2,6 +2,7 @@ disabled_rules: - file_length - line_length - type_body_length + - vertical_whitespace excluded: - Carthage - Pods diff --git a/CHANGELOG.md b/CHANGELOG.md index 68e898a..2505371 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## v1.3.0 + +* Swift 3.0 +* Support `pod try ICInputAccessory` + ## v1.2.1 * Update to Xcode 8.2 @@ -8,10 +13,9 @@ ## v1.1.0 +* Swift 2.2 * Support storyboard * Support subspecs -* Upgrade to Swift 2.2 -* Use CocoaPods (1.0.1) ## v1.0.0 diff --git a/Dangerfile b/Dangerfile new file mode 100644 index 0000000..f54a8bc --- /dev/null +++ b/Dangerfile @@ -0,0 +1,24 @@ +#!/usr/bin/env ruby + +# Sometimes it's a README fix, or something like that - which isn't relevant for +# including in a project's CHANGELOG for example +declared_trivial = (github.pr_title + github.pr_body).include? "#trivial" + +# Make it more obvious that a PR is a work in progress and shouldn't be merged yet +warn "PR is classed as Work in Progress" if github.pr_title.include? "[WIP]" + +# Warn when there is a big PR +warn "Big PR" if git.lines_of_code > 500 + +# Ensure there is a summary for a PR +fail "Please provide a summary in the Pull Request description" if github.pr_body.length < 5 + +# Add a CHANGELOG entry for app changes +if git.lines_of_code > 50 && !git.modified_files.include?("CHANGELOG.md") && !declared_trivial + fail "Please update [CHANGELOG.md](https://github.com/polydice/ICInputAccessory/blob/develop/CHANGELOG.md).", sticky: true +end + +# Ensure a clean commits history +if git.commits.any? { |c| c.message =~ /^Merge branch/ } + fail "Please rebase to get rid of the merge commits in this PR", sticky: true +end diff --git a/Example/Example.xcodeproj/project.pbxproj b/Example.xcodeproj/project.pbxproj similarity index 96% rename from Example/Example.xcodeproj/project.pbxproj rename to Example.xcodeproj/project.pbxproj index aeaf679..8718c1c 100644 --- a/Example/Example.xcodeproj/project.pbxproj +++ b/Example.xcodeproj/project.pbxproj @@ -49,9 +49,9 @@ B5E9F9081C8D3B6E00443DC7 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; B5E9F90A1C8D3B6E00443DC7 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; B5F62A5C1C9ECBCB003A1231 /* ICKeyboardDismissTextFieldUITests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ICKeyboardDismissTextFieldUITests.swift; sourceTree = ""; }; - CA708B7D49E7D80A75ED81E3 /* Pods-Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Example.debug.xcconfig"; path = "../Pods/Target Support Files/Pods-Example/Pods-Example.debug.xcconfig"; sourceTree = ""; }; + CA708B7D49E7D80A75ED81E3 /* Pods-Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Example.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Example/Pods-Example.debug.xcconfig"; sourceTree = ""; }; D0DB1D3E89AB75183DB104E0 /* Pods_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - FE1A89C8A77ED0438A206A24 /* Pods-Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Example.release.xcconfig"; path = "../Pods/Target Support Files/Pods-Example/Pods-Example.release.xcconfig"; sourceTree = ""; }; + FE1A89C8A77ED0438A206A24 /* Pods-Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Example.release.xcconfig"; path = "Pods/Target Support Files/Pods-Example/Pods-Example.release.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -254,7 +254,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/../Pods/Target Support Files/Pods-Example/Pods-Example-resources.sh\"\n"; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Example/Pods-Example-resources.sh\"\n"; showEnvVarsInLog = 0; }; 96705876C946719953BCD0C6 /* [CP] Check Pods Manifest.lock */ = { @@ -284,7 +284,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "if which swiftlint >/dev/null; then swiftlint; fi"; + shellScript = "sh ${SRCROOT}/scripts/swiftlint.sh"; }; CAB3B20531AAE2438C48D751 /* [CP] Embed Pods Frameworks */ = { isa = PBXShellScriptBuildPhase; @@ -298,7 +298,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/../Pods/Target Support Files/Pods-Example/Pods-Example-frameworks.sh\"\n"; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Example/Pods-Example-frameworks.sh\"\n"; showEnvVarsInLog = 0; }; /* End PBXShellScriptBuildPhase section */ @@ -359,11 +359,12 @@ B548C5C91C8E91B0009D5AEE /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = "$(inherited)"; INFOPLIST_FILE = ICInputAccessoryUITests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.polydice.ICInputAccessoryUITests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 2.3; + SWIFT_VERSION = 3.0; TEST_TARGET_NAME = Example; USES_XCTRUNNER = YES; }; @@ -372,11 +373,13 @@ B548C5CA1C8E91B0009D5AEE /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = "$(inherited)"; INFOPLIST_FILE = ICInputAccessoryUITests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.polydice.ICInputAccessoryUITests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 2.3; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = 3.0; TEST_TARGET_NAME = Example; USES_XCTRUNNER = YES; }; @@ -426,7 +429,7 @@ ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 2.3; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -467,7 +470,7 @@ MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 2.3; + SWIFT_VERSION = 3.0; VALIDATE_PRODUCT = YES; }; name = Release; @@ -483,7 +486,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.polydice.ICInputAccessoryExample; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 2.3; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -499,7 +502,8 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.polydice.ICInputAccessoryExample; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 2.3; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; diff --git a/Example/Example.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/Example.xcodeproj/project.xcworkspace/contents.xcworkspacedata similarity index 100% rename from Example/Example.xcodeproj/project.xcworkspace/contents.xcworkspacedata rename to Example.xcodeproj/project.xcworkspace/contents.xcworkspacedata diff --git a/Example/Example.xcodeproj/xcshareddata/xcschemes/Example.xcscheme b/Example.xcodeproj/xcshareddata/xcschemes/Example.xcscheme similarity index 100% rename from Example/Example.xcodeproj/xcshareddata/xcschemes/Example.xcscheme rename to Example.xcodeproj/xcshareddata/xcschemes/Example.xcscheme diff --git a/Example/.swiftlint.yml b/Example/.swiftlint.yml deleted file mode 100644 index 01084bb..0000000 --- a/Example/.swiftlint.yml +++ /dev/null @@ -1,6 +0,0 @@ -disabled_rules: - - file_length - - line_length - - type_body_length -included: - - ../Source diff --git a/Example/Example/AppDelegate.swift b/Example/AppDelegate.swift similarity index 85% rename from Example/Example/AppDelegate.swift rename to Example/AppDelegate.swift index 3e21da6..23c28d5 100644 --- a/Example/Example/AppDelegate.swift +++ b/Example/AppDelegate.swift @@ -31,9 +31,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { - window = UIWindow(frame: UIScreen.mainScreen().bounds) - window?.backgroundColor = UIColor.whiteColor() + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool { + window = UIWindow(frame: UIScreen.main.bounds) + window?.backgroundColor = UIColor.white window?.rootViewController = UINavigationController(rootViewController: ExampleViewController()) window?.makeKeyAndVisible() return true diff --git a/Example/Example/Assets.xcassets/AppIcon.appiconset/Contents.json b/Example/Assets.xcassets/AppIcon.appiconset/Contents.json similarity index 100% rename from Example/Example/Assets.xcassets/AppIcon.appiconset/Contents.json rename to Example/Assets.xcassets/AppIcon.appiconset/Contents.json diff --git a/Example/Example/Assets.xcassets/Contents.json b/Example/Assets.xcassets/Contents.json similarity index 100% rename from Example/Example/Assets.xcassets/Contents.json rename to Example/Assets.xcassets/Contents.json diff --git a/Example/Example/Assets.xcassets/icook-iphone-input-search.imageset/Contents.json b/Example/Assets.xcassets/icook-iphone-input-search.imageset/Contents.json similarity index 100% rename from Example/Example/Assets.xcassets/icook-iphone-input-search.imageset/Contents.json rename to Example/Assets.xcassets/icook-iphone-input-search.imageset/Contents.json diff --git a/Example/Example/Assets.xcassets/icook-iphone-input-search.imageset/icook-iphone-input-search.pdf b/Example/Assets.xcassets/icook-iphone-input-search.imageset/icook-iphone-input-search.pdf similarity index 100% rename from Example/Example/Assets.xcassets/icook-iphone-input-search.imageset/icook-iphone-input-search.pdf rename to Example/Assets.xcassets/icook-iphone-input-search.imageset/icook-iphone-input-search.pdf diff --git a/Example/Example/Base.lproj/InfoPlist.strings b/Example/Base.lproj/InfoPlist.strings similarity index 100% rename from Example/Example/Base.lproj/InfoPlist.strings rename to Example/Base.lproj/InfoPlist.strings diff --git a/Example/Example/Base.lproj/LaunchScreen.storyboard b/Example/Base.lproj/LaunchScreen.storyboard similarity index 100% rename from Example/Example/Base.lproj/LaunchScreen.storyboard rename to Example/Base.lproj/LaunchScreen.storyboard diff --git a/Example/Example/CustomizedTokenField.swift b/Example/CustomizedTokenField.swift similarity index 74% rename from Example/Example/CustomizedTokenField.swift rename to Example/CustomizedTokenField.swift index 4f8698a..b79d4fb 100644 --- a/Example/Example/CustomizedTokenField.swift +++ b/Example/CustomizedTokenField.swift @@ -52,31 +52,31 @@ extension ICTokenField { layer.cornerRadius = 5 layer.shouldRasterize = true - layer.rasterizationScale = UIScreen.mainScreen().scale + layer.rasterizationScale = UIScreen.main.scale backgroundColor = UIColor(red:0.8, green:0.32, blue:0.24, alpha:1) - textField.textColor = UIColor.whiteColor() - textField.tintColor = UIColor.whiteColor() - textField.font = UIFont.boldSystemFontOfSize(14) + textField.textColor = UIColor.white + textField.tintColor = UIColor.white + textField.font = UIFont.boldSystemFont(ofSize: 14) attributedPlaceholder = NSAttributedString( - string: String(self.dynamicType), + string: String(describing: type(of: self)), attributes: [ - NSForegroundColorAttributeName: UIColor.whiteColor().colorWithAlphaComponent(0.5), - NSFontAttributeName: UIFont.boldSystemFontOfSize(14) + NSForegroundColorAttributeName: UIColor.white.withAlphaComponent(0.5), + NSFontAttributeName: UIFont.boldSystemFont(ofSize: 14) ] ) normalTokenAttributes = [ - NSForegroundColorAttributeName: UIColor.whiteColor(), - NSBackgroundColorAttributeName: UIColor.whiteColor().colorWithAlphaComponent(0.25), - NSFontAttributeName: UIFont.boldSystemFontOfSize(14) + NSForegroundColorAttributeName: UIColor.white, + NSBackgroundColorAttributeName: UIColor.white.withAlphaComponent(0.25), + NSFontAttributeName: UIFont.boldSystemFont(ofSize: 14) ] highlightedTokenAttributes = [ NSForegroundColorAttributeName: UIColor(red:0.8, green:0.32, blue:0.24, alpha:1), - NSBackgroundColorAttributeName: UIColor.whiteColor(), - NSFontAttributeName: UIFont.boldSystemFontOfSize(14) + NSBackgroundColorAttributeName: UIColor.white, + NSFontAttributeName: UIFont.boldSystemFont(ofSize: 14) ] } diff --git a/Example/Example/CustomizedTokenViewController.swift b/Example/CustomizedTokenViewController.swift similarity index 68% rename from Example/Example/CustomizedTokenViewController.swift rename to Example/CustomizedTokenViewController.swift index 2f7ae64..907ef61 100644 --- a/Example/Example/CustomizedTokenViewController.swift +++ b/Example/CustomizedTokenViewController.swift @@ -36,73 +36,74 @@ class CustomizedTokenViewController: UIViewController, ICTokenFieldDelegate { override func loadView() { super.loadView() - view.backgroundColor = UIColor.whiteColor() - textView.text = "[\n\n]"; - textView.font = UIFont.preferredFontForTextStyle(UIFontTextStyleSubheadline) + view.backgroundColor = UIColor.white + textView.text = "[\n\n]" + textView.font = UIFont.preferredFont(forTextStyle: .subheadline) textView.frame = view.bounds.insetBy(dx: 10, dy: 10) - textView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight] + textView.autoresizingMask = [.flexibleWidth, .flexibleHeight] view.addSubview(textView) } override func viewDidLoad() { super.viewDidLoad() navigationController?.navigationBar.barTintColor = UIColor(red:0.96, green:0.48, blue:0.4, alpha:1) - navigationController?.navigationBar.translucent = false - navigationController?.navigationBar.barStyle = .Black + navigationController?.navigationBar.isTranslucent = false + navigationController?.navigationBar.barStyle = .black - let cancelBarButton = UIBarButtonItem(barButtonSystemItem: .Cancel, target: self, action: .dismiss) - cancelBarButton.tintColor = UIColor.whiteColor() + let cancelBarButton = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: .dismiss) + cancelBarButton.tintColor = UIColor.white navigationItem.rightBarButtonItem = cancelBarButton navigationItem.titleView = tokenField tokenField.delegate = self } - override func viewWillAppear(animated: Bool) { + override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) - tokenField.becomeFirstResponder() + _ = tokenField.becomeFirstResponder() } - override func viewWillDisappear(animated: Bool) { + override func viewWillDisappear(_ animated: Bool) { super.viewWillAppear(animated) - tokenField.resignFirstResponder() + _ = tokenField.resignFirstResponder() textView.endEditing(true) } // MARK: - ICTokenFieldDelegate - func tokenFieldDidBeginEditing(tokenField: ICTokenField) { + func tokenFieldDidBeginEditing(_ tokenField: ICTokenField) { print(#function) } - func tokenFieldDidEndEditing(tokenField: ICTokenField) { + func tokenFieldDidEndEditing(_ tokenField: ICTokenField) { print(#function) } - func tokenFieldWillReturn(tokenField: ICTokenField) { + func tokenFieldWillReturn(_ tokenField: ICTokenField) { print(#function) } - func tokenField(tokenField: ICTokenField, didEnterText text: String) { + func tokenField(_ tokenField: ICTokenField, didEnterText text: String) { print("Add: \"\(text)\"") updateTexts() } - func tokenField(tokenField: ICTokenField, didDeleteText text: String, atIndex index: Int) { + func tokenField(_ tokenField: ICTokenField, didDeleteText text: String, atIndex index: Int) { print("Delete: \"\(text)\"") updateTexts() } // MARK: - UIResponder Callbacks - @objc private func dismiss(sender: UIBarButtonItem) { - presentingViewController?.dismissViewControllerAnimated(true, completion: nil) + @objc fileprivate func dismiss(_ sender: UIBarButtonItem) { + presentingViewController?.dismiss(animated: true, completion: nil) } // MARK: - Private Methods private func updateTexts() { - textView.text = "[\n " + tokenField.texts.map { "\"" + $0 + "\"" } .joinWithSeparator(",\n ") + "\n]" + let tokens = tokenField.texts.map { "\"" + $0 + "\"" } .joined(separator: ",\n ") + textView.text = "[\n " + tokens + "\n]" } } diff --git a/Example/Example/ExampleCell.swift b/Example/ExampleCell.swift similarity index 77% rename from Example/Example/ExampleCell.swift rename to Example/ExampleCell.swift index 13b8379..a5cc615 100644 --- a/Example/Example/ExampleCell.swift +++ b/Example/ExampleCell.swift @@ -36,14 +36,14 @@ class ExampleCell: UITableViewCell { displayingView.translatesAutoresizingMaskIntoConstraints = false if #available(iOS 9.0, *) { - displayingView.topAnchor.constraintEqualToAnchor(contentView.topAnchor).active = true - displayingView.leftAnchor.constraintEqualToAnchor(contentView.leftAnchor).active = true - displayingView.bottomAnchor.constraintEqualToAnchor(contentView.bottomAnchor).active = true - displayingView.rightAnchor.constraintEqualToAnchor(contentView.rightAnchor).active = true + displayingView.topAnchor.constraint(equalTo: contentView.topAnchor).isActive = true + displayingView.leftAnchor.constraint(equalTo: contentView.leftAnchor).isActive = true + displayingView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor).isActive = true + displayingView.rightAnchor.constraint(equalTo: contentView.rightAnchor).isActive = true } else { let views = ["view": displayingView] - contentView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[view]|", options: [], metrics: nil, views: views)) - contentView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|[view]|", options: [], metrics: nil, views: views)) + contentView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|[view]|", options: [], metrics: nil, views: views)) + contentView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|[view]|", options: [], metrics: nil, views: views)) } } } @@ -56,7 +56,7 @@ class ExampleCell: UITableViewCell { showcase?.removeFromSuperview() showcase = nil textLabel?.text = nil - accessoryType = .None + accessoryType = .none } } diff --git a/Example/Example/ExampleViewController.swift b/Example/ExampleViewController.swift similarity index 62% rename from Example/Example/ExampleViewController.swift rename to Example/ExampleViewController.swift index f9c6c4f..fcbe458 100644 --- a/Example/Example/ExampleViewController.swift +++ b/Example/ExampleViewController.swift @@ -36,17 +36,17 @@ class ExampleViewController: UITableViewController { ] private lazy var flipButton: UIButton = { - let _button = UIButton(type: .System) - _button.frame = CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.width, height: 88) - _button.setTitle("Storyboard", forState: .Normal) - _button.addTarget(self, action: .showStoryboard, forControlEvents: .TouchUpInside) + let _button = UIButton(type: .system) + _button.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 88) + _button.setTitle("Storyboard", for: UIControlState()) + _button.addTarget(self, action: .showStoryboard, for: .touchUpInside) return _button }() // MARK: - Initialization convenience init() { - self.init(style: .Grouped) + self.init(style: .grouped) title = "ICInputAccessory" } @@ -54,22 +54,22 @@ class ExampleViewController: UITableViewController { override func loadView() { super.loadView() - tableView.registerClass(ExampleCell.self, forCellReuseIdentifier: NSStringFromClass(ExampleCell.self)) + tableView.register(ExampleCell.self, forCellReuseIdentifier: String(describing: ExampleCell.self)) tableView.tableFooterView = flipButton - tableView.tableFooterView?.userInteractionEnabled + tableView.tableFooterView?.isUserInteractionEnabled = true } // MARK: - UITableViewDataSource - override func numberOfSectionsInTableView(tableView: UITableView) -> Int { + override func numberOfSections(in tableView: UITableView) -> Int { return types.count } - override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return 1 } - override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? { + override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { switch types[section] { case is ICKeyboardDismissTextField.Type: return "Dismiss Keyboard" @@ -82,26 +82,27 @@ class ExampleViewController: UITableViewController { } } - override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { - let cell = tableView.dequeueReusableCellWithIdentifier(NSStringFromClass(ExampleCell.self), forIndexPath: indexPath) + override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: ExampleCell.self), for: indexPath) + switch types[indexPath.section] { case let type as ICKeyboardDismissTextField.Type: let textField = type.init() - textField.leftViewMode = .Always + textField.leftViewMode = .always textField.leftView = UIView(frame: CGRect(x: 0, y: 0, width: 15, height: 15)) - textField.placeholder = String(type) + textField.placeholder = String(describing: type) (cell as? ExampleCell)?.showcase = textField case let type as CustomizedTokenField.Type: - cell.textLabel?.text = String(type) - cell.accessoryType = .DisclosureIndicator + cell.textLabel?.text = String(describing: type) + cell.accessoryType = .disclosureIndicator case let type as ICTokenField.Type: let container = UIView(frame: cell.bounds) let tokenField = type.init() - tokenField.placeholder = String(type) + tokenField.placeholder = String(describing: type) tokenField.frame = container.bounds.insetBy(dx: 5, dy: 0) - tokenField.autoresizingMask = [.FlexibleWidth, .FlexibleHeight] + tokenField.autoresizingMask = [.flexibleWidth, .flexibleHeight] container.addSubview(tokenField) (cell as? ExampleCell)?.showcase = container @@ -113,22 +114,22 @@ class ExampleViewController: UITableViewController { // MARK: - UITableViewDelegate - override func tableView(tableView: UITableView, shouldHighlightRowAtIndexPath indexPath: NSIndexPath) -> Bool { + override func tableView(_ tableView: UITableView, shouldHighlightRowAt indexPath: IndexPath) -> Bool { return types[indexPath.section] == CustomizedTokenField.self } - override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { + override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { if types[indexPath.section] == CustomizedTokenField.self { - presentViewController(UINavigationController(rootViewController: CustomizedTokenViewController()), animated: true, completion: nil) + present(UINavigationController(rootViewController: CustomizedTokenViewController()), animated: true, completion: nil) } } // MARK: - UIResponder Callbacks - @objc private func showStoryboard(sender: UIButton) { - if let controller = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle()).instantiateInitialViewController() { - controller.modalTransitionStyle = .FlipHorizontal - presentViewController(controller, animated: true, completion: nil) + @objc fileprivate func showStoryboard(_ sender: UIButton) { + if let controller = UIStoryboard(name: "Main", bundle: Bundle.main).instantiateInitialViewController() { + controller.modalTransitionStyle = .flipHorizontal + present(controller, animated: true, completion: nil) } } diff --git a/Example/Example/Info.plist b/Example/Info.plist similarity index 98% rename from Example/Example/Info.plist rename to Example/Info.plist index 3fc855b..eee55eb 100644 --- a/Example/Example/Info.plist +++ b/Example/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.2.1 + 1.3.0 CFBundleSignature ???? CFBundleVersion diff --git a/Example/Example/Main.storyboard b/Example/Main.storyboard similarity index 100% rename from Example/Example/Main.storyboard rename to Example/Main.storyboard diff --git a/Example/Example/StoryboardViewController.swift b/Example/StoryboardViewController.swift similarity index 78% rename from Example/Example/StoryboardViewController.swift rename to Example/StoryboardViewController.swift index 11936b7..955b448 100644 --- a/Example/Example/StoryboardViewController.swift +++ b/Example/StoryboardViewController.swift @@ -32,19 +32,19 @@ class StoryboardViewController: UITableViewController { @IBOutlet weak var tokenField: ICTokenField! { didSet { tokenField.normalTokenAttributes = [ - NSForegroundColorAttributeName: UIColor.whiteColor(), - NSBackgroundColorAttributeName: UIColor.whiteColor().colorWithAlphaComponent(0.25), + NSForegroundColorAttributeName: UIColor.white, + NSBackgroundColorAttributeName: UIColor.white.withAlphaComponent(0.25) ] tokenField.highlightedTokenAttributes = [ - NSForegroundColorAttributeName: UIColor.darkGrayColor(), - NSBackgroundColorAttributeName: UIColor.whiteColor(), + NSForegroundColorAttributeName: UIColor.darkGray, + NSBackgroundColorAttributeName: UIColor.white ] } } - @IBAction func dismiss(sender: UIButton) { - presentingViewController?.dismissViewControllerAnimated(true, completion: nil) + @IBAction func dismiss(_ sender: UIButton) { + presentingViewController?.dismiss(animated: true, completion: nil) } } diff --git a/Gemfile b/Gemfile index d6c4f84..df55500 100644 --- a/Gemfile +++ b/Gemfile @@ -2,6 +2,7 @@ source "http://rubygems.org" ruby "2.3.1" gem "cocoapods", "~> 1.1.0" +gem "danger", "~> 4.0.0" gem "jazzy", "~> 0.7.0" gem "pry" gem "rake" diff --git a/Gemfile.lock b/Gemfile.lock index 72e0625..65513a9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,14 +1,20 @@ GEM remote: http://rubygems.org/ specs: - CFPropertyList (2.3.4) + CFPropertyList (2.3.5) activesupport (4.2.7.1) i18n (~> 0.7) json (~> 1.7, >= 1.7.7) minitest (~> 5.1) thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) + addressable (2.5.0) + public_suffix (~> 2.0, >= 2.0.2) claide (1.0.1) + claide-plugins (0.9.2) + cork + nap + open4 (~> 1.3) cocoapods (1.1.1) activesupport (>= 4.0.2, < 5) claide (>= 1.0.1, < 2.0) @@ -43,10 +49,28 @@ GEM cocoapods-try (1.1.0) coderay (1.1.1) colored (1.2) + cork (0.2.0) + colored (~> 1.2) + danger (4.0.5) + claide (~> 1.0) + claide-plugins (>= 0.9.2) + colored (~> 1.2) + cork (~> 0.1) + faraday (~> 0.9) + faraday-http-cache (~> 1.0) + git (~> 1) + kramdown (~> 1.5) + octokit (~> 4.2) + terminal-table (~> 1) escape (0.0.4) + faraday (0.11.0) + multipart-post (>= 1.2, < 3) + faraday-http-cache (1.3.1) + faraday (~> 0.8) fourflusher (2.0.1) fuzzy_match (2.0.4) - gh_inspector (1.0.2) + gh_inspector (1.0.3) + git (1.3.0) i18n (0.7.0) jazzy (0.7.3) cocoapods (~> 1.0) @@ -57,29 +81,40 @@ GEM sass (~> 3.4) sqlite3 (~> 1.3) xcinvoke (~> 0.3.0) - json (1.8.3) + json (1.8.6) + kramdown (1.13.2) liferaft (0.0.6) method_source (0.8.2) minitest (5.10.1) - molinillo (0.5.4) + molinillo (0.5.5) + multipart-post (2.0.0) mustache (0.99.8) nanaimo (0.2.3) nap (1.1.0) netrc (0.7.8) + octokit (4.6.2) + sawyer (~> 0.8.0, >= 0.5.3) open4 (1.3.4) pry (0.10.4) coderay (~> 1.1.0) method_source (~> 0.8.1) slop (~> 3.4) + public_suffix (2.0.5) rake (12.0.0) redcarpet (3.4.0) rouge (1.11.1) sass (3.4.23) + sawyer (0.8.1) + addressable (>= 2.3.5, < 2.6) + faraday (~> 0.8, < 1.0) slop (3.6.0) - sqlite3 (1.3.12) + sqlite3 (1.3.13) + terminal-table (1.7.3) + unicode-display_width (~> 1.1.1) thread_safe (0.3.5) tzinfo (1.2.2) thread_safe (~> 0.1) + unicode-display_width (1.1.3) xcinvoke (0.3.0) liferaft (~> 0.0.6) xcodeproj (1.4.2) @@ -96,6 +131,7 @@ PLATFORMS DEPENDENCIES cocoapods (~> 1.1.0) + danger (~> 4.0.0) jazzy (~> 0.7.0) pry rake diff --git a/ICInputAccessory.podspec b/ICInputAccessory.podspec index 185836e..f5a705d 100644 --- a/ICInputAccessory.podspec +++ b/ICInputAccessory.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "ICInputAccessory" - s.version = "1.2.1" + s.version = "1.3.0" s.summary = "A customized token text field used in the iCook app." s.description = <<-DESC ICKeyboardDismissTextField: diff --git a/ICInputAccessory.xcodeproj/project.pbxproj b/ICInputAccessory.xcodeproj/project.pbxproj index 26bd8c0..fd4226c 100644 --- a/ICInputAccessory.xcodeproj/project.pbxproj +++ b/ICInputAccessory.xcodeproj/project.pbxproj @@ -132,6 +132,7 @@ TargetAttributes = { B56BC4291C89A7EA00C20AD6 = { CreatedOnToolsVersion = 7.2.1; + LastSwiftMigration = 0820; }; }; }; @@ -225,7 +226,7 @@ ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 2.3; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -269,7 +270,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 8.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; - SWIFT_VERSION = 2.3; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -294,7 +295,7 @@ PRODUCT_NAME = ICInputAccessory; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 2.3; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -315,7 +316,7 @@ PRODUCT_NAME = ICInputAccessory; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 2.3; + SWIFT_VERSION = 3.0; }; name = Release; }; diff --git a/ICInputAccessory.xcworkspace/contents.xcworkspacedata b/ICInputAccessory.xcworkspace/contents.xcworkspacedata index 330fda0..e35a8e1 100644 --- a/ICInputAccessory.xcworkspace/contents.xcworkspacedata +++ b/ICInputAccessory.xcworkspace/contents.xcworkspacedata @@ -2,10 +2,10 @@ + location = "group:ICInputAccessory.xcodeproj"> + location = "group:Example.xcodeproj"> diff --git a/ICInputAccessory/Info.plist b/ICInputAccessory/Info.plist index ae2dbbb..9f4a4aa 100644 --- a/ICInputAccessory/Info.plist +++ b/ICInputAccessory/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 1.2.1 + 1.3.0 CFBundleSignature ???? CFBundleVersion diff --git a/Example/ICInputAccessoryUITests/ICKeyboardDismissTextFieldUITests.swift b/ICInputAccessoryUITests/ICKeyboardDismissTextFieldUITests.swift similarity index 78% rename from Example/ICInputAccessoryUITests/ICKeyboardDismissTextFieldUITests.swift rename to ICInputAccessoryUITests/ICKeyboardDismissTextFieldUITests.swift index eee899c..a7f5f3a 100644 --- a/Example/ICInputAccessoryUITests/ICKeyboardDismissTextFieldUITests.swift +++ b/ICInputAccessoryUITests/ICKeyboardDismissTextFieldUITests.swift @@ -45,9 +45,9 @@ class ICKeyboardDismissTextFieldUITests: XCTestCase { let app = XCUIApplication() app.tables.cells.textFields["ICKeyboardDismissTextField"].tap() - let keyboardWindow = app.childrenMatchingType(.Window).elementBoundByIndex(1) - let accessory = keyboardWindow.childrenMatchingType(.Other).element.childrenMatchingType(.Other).element.childrenMatchingType(.Other).elementBoundByIndex(0) - accessory.childrenMatchingType(.Button).element.tap() + let keyboardWindow = app.children(matching: .window).element(boundBy: 1) + let accessory = keyboardWindow.children(matching: .other).element.children(matching: .other).element.children(matching: .other).element(boundBy: 0) + accessory.children(matching: .button).element.tap() } func testStoryboard() { @@ -57,11 +57,11 @@ class ICKeyboardDismissTextFieldUITests: XCTestCase { tablesQuery.buttons["Storyboard"].tap() tablesQuery.textFields["Storyboard ICKeyboardDismissTextField"].tap() - let keyboardWindow = app.childrenMatchingType(.Window).elementBoundByIndex(1) - let accessory = keyboardWindow.childrenMatchingType(.Other).element.childrenMatchingType(.Other).element.childrenMatchingType(.Other).elementBoundByIndex(0) - accessory.childrenMatchingType(.Button).element.tap() + let keyboardWindow = app.children(matching: .window).element(boundBy: 1) + let accessory = keyboardWindow.children(matching: .other).element.children(matching: .other).element.children(matching: .other).element(boundBy: 0) + accessory.children(matching: .button).element.tap() tablesQuery.buttons["Back to Code"].tap() } -} \ No newline at end of file +} diff --git a/Example/ICInputAccessoryUITests/ICTokenFieldUITests.swift b/ICInputAccessoryUITests/ICTokenFieldUITests.swift similarity index 91% rename from Example/ICInputAccessoryUITests/ICTokenFieldUITests.swift rename to ICInputAccessoryUITests/ICTokenFieldUITests.swift index 4290f36..45624a1 100644 --- a/Example/ICInputAccessoryUITests/ICTokenFieldUITests.swift +++ b/ICInputAccessoryUITests/ICTokenFieldUITests.swift @@ -44,7 +44,7 @@ class ICTokenFieldUITests: XCTestCase { func testTokenField() { let app = XCUIApplication() let tablesQuery = app.tables - let textField = tablesQuery.cells.containingType(.StaticText, identifier:"ICTokenField").childrenMatchingType(.TextField).element + let textField = tablesQuery.cells.containing(.staticText, identifier:"ICTokenField").children(matching: .textField).element textField.tap() textField.typeText("Try") @@ -69,7 +69,7 @@ class ICTokenFieldUITests: XCTestCase { let app = XCUIApplication() app.tables.staticTexts["CustomizedTokenField"].tap() - let tokenField = app.navigationBars["Example.CustomizedTokenView"].scrollViews.childrenMatchingType(.TextField).element + let tokenField = app.navigationBars["Example.CustomizedTokenView"].scrollViews.children(matching: .textField).element tokenField.typeText("Try") tokenField.typeText(" ") tokenField.typeText("iCook") @@ -93,7 +93,7 @@ class ICTokenFieldUITests: XCTestCase { let tablesQuery = app.tables tablesQuery.buttons["Storyboard"].tap() - let tokenField = tablesQuery.cells.containingType(.StaticText, identifier:"Storyboard ICTokenField").childrenMatchingType(.TextField).element + let tokenField = tablesQuery.cells.containing(.staticText, identifier:"Storyboard ICTokenField").children(matching: .textField).element tokenField.tap() tokenField.typeText("Try") tokenField.typeText(" ") diff --git a/Example/ICInputAccessoryUITests/Info.plist b/ICInputAccessoryUITests/Info.plist similarity index 96% rename from Example/ICInputAccessoryUITests/Info.plist rename to ICInputAccessoryUITests/Info.plist index b91171f..3fee538 100644 --- a/Example/ICInputAccessoryUITests/Info.plist +++ b/ICInputAccessoryUITests/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType BNDL CFBundleShortVersionString - 1.2.1 + 1.3.0 CFBundleSignature ???? CFBundleVersion diff --git a/Makefile b/Makefile index 0c60fef..8b63836 100644 --- a/Makefile +++ b/Makefile @@ -19,4 +19,6 @@ carthage: set -o pipefail && carthage build --no-skip-current --verbose | bundle exec xcpretty docs: + rm -rfv docs + git clone -b gh-pages --single-branch https://github.com/polydice/ICInputAccessory.git docs bundle exec jazzy --config .jazzy.yml diff --git a/Podfile b/Podfile index f03069f..5134de8 100644 --- a/Podfile +++ b/Podfile @@ -3,7 +3,7 @@ use_frameworks! workspace "ICInputAccessory" project "ICInputAccessory" -project "Example/Example" +project "Example" target "Example" do pod "ICInputAccessory/KeyboardDismissTextField", path: "./" @@ -13,7 +13,7 @@ end post_install do |installer| installer.pods_project.targets.each do |target| target.build_configurations.each do |config| - config.build_settings["SWIFT_VERSION"] = "2.3" + config.build_settings["SWIFT_VERSION"] = "3.0" config.build_settings['CONFIGURATION_BUILD_DIR'] = '$PODS_CONFIGURATION_BUILD_DIR' end end diff --git a/Podfile.lock b/Podfile.lock index b6f916c..4f47d31 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -1,6 +1,6 @@ PODS: - - ICInputAccessory/KeyboardDismissTextField (1.2.1) - - ICInputAccessory/TokenField (1.2.1) + - ICInputAccessory/KeyboardDismissTextField (1.3.0) + - ICInputAccessory/TokenField (1.3.0) DEPENDENCIES: - ICInputAccessory/KeyboardDismissTextField (from `./`) @@ -11,8 +11,8 @@ EXTERNAL SOURCES: :path: "./" SPEC CHECKSUMS: - ICInputAccessory: 19865bd3efb918c22f8b7b5715566b85bc8b4577 + ICInputAccessory: e9142958152461ddb627e78e3f1f0a8b263b7271 -PODFILE CHECKSUM: b125d926ec250330789d257be95f39437c2e5c9c +PODFILE CHECKSUM: 6e8fb9f23fc92d92278fbf08ca8ef072ef28a486 COCOAPODS: 1.1.1 diff --git a/README.md b/README.md index 25732d4..97b2500 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,8 @@ Try . [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg)](https://github.com/Carthage/Carthage) [![CocoaPods Compatible](https://img.shields.io/cocoapods/v/ICInputAccessory.svg)](https://cocoapods.org/pods/ICInputAccessory) ![Platform](https://img.shields.io/cocoapods/p/ICInputAccessory.svg) -[![Docs](https://img.shields.io/cocoapods/metrics/doc-percent/ICInputAccessory.svg)](http://cocoadocs.org/docsets/ICInputAccessory/) -![Swift 2.3](https://img.shields.io/badge/Swift-2.3-orange.svg) +[![CocoaDocs](https://img.shields.io/cocoapods/metrics/doc-percent/ICInputAccessory.svg)](http://cocoadocs.org/docsets/ICInputAccessory/) +![Swift 3.0](https://img.shields.io/badge/Swift-3.0-orange.svg) ### ICKeyboardDismissTextField @@ -30,35 +30,38 @@ ICInputAccessory | iOS | Xcode | Swift `~> 1.0.0` | 8.0+ | 7.2 | ![Swift 2.1.1](https://img.shields.io/badge/Swift-2.1.1-orange.svg) `~> 1.1.0` | 8.0+ | 7.3 | ![Swift 2.2](https://img.shields.io/badge/Swift-2.2-orange.svg) `~> 1.2.0` | 8.0+ | 8.0 | ![Swift 2.3](https://img.shields.io/badge/Swift-2.3-orange.svg) -`feature/swift-3`| 8.0+ | 8.0 | ![Swift 3.0](https://img.shields.io/badge/Swift-3.0-orange.svg) +`~> 1.3.0` | 8.0+ | 8.0 | ![Swift 3.0](https://img.shields.io/badge/Swift-3.0-orange.svg) ## Installation -### Install via [Carthage](https://github.com/Carthage/Carthage) +### Use [Carthage](https://github.com/Carthage/Carthage) -* Create a `Cartfile` with the following specification and run `carthage update`. +Create a `Cartfile` with the following specification and run `carthage update ICInputAccessory`. Follow the [instructions](https://github.com/Carthage/Carthage#if-youre-building-for-ios) to add the framework to an iOS project. - ``` - github "polydice/ICInputAccessory" - ``` +``` +github "polydice/ICInputAccessory" +``` -* Follow the [instruction](https://github.com/Carthage/Carthage#if-youre-building-for-ios) to add the framework to an iOS project. +### Use [CocoaPods](http://guides.cocoapods.org/) -### Install via [CocoaPods](http://guides.cocoapods.org/) +**ICInputAccessory** supports subspecs. Create a `Podfile` with the following specification and run `pod install`. -* **ICInputAccessory** supports subspecs. Create a `Podfile` with the following specification and run `pod install`. +```rb +platform :ios, '8.0' +use_frameworks! - ```rb - platform :ios, '8.0' - use_frameworks! +pod 'ICInputAccessory/TokenField' +pod 'ICInputAccessory/KeyboardDismissTextField' +``` - pod 'ICInputAccessory/TokenField' - pod 'ICInputAccessory/KeyboardDismissTextField' - ``` +### Use Git Submodule -### Install Manually +``` +git submodule add -b master git@github.com:polydice/ICInputAccessory.git Dependencies/ICInputAccessory +``` -* Everything you need resides in the `Source` directory. Drag those files to a project. +* Everything you need resides in the `Source` directory. Add those files to your project. +* Alternatively, drag **ICInputAccessory.xcodeproj** to your app project as a subproject. Add **ICInputAccessory-iOS** to the **Target Dependencies** in the application target's **Build Phases** settings. ## Usage @@ -162,6 +165,7 @@ Please fork this repository, create a branch named like `feature/some-new-featur ## Contact [![Twitter](https://img.shields.io/badge/twitter-@polydice-blue.svg?style=flat)](https://twitter.com/polydice) +[![Join the chat at https://gitter.im/polydice/ICInputAccessory](https://badges.gitter.im/polydice/ICInputAccessory.svg)](https://gitter.im/polydice/ICInputAccessory) ## License diff --git a/Rakefile b/Rakefile index 7395976..6cac13b 100644 --- a/Rakefile +++ b/Rakefile @@ -23,6 +23,7 @@ namespace :ci do end end + namespace :example do desc "Build the example project" task :build, [:os] do |t, args| @@ -47,3 +48,33 @@ namespace :framework do exit $?.exitstatus if not $?.success? end end + + +desc "Bump versions" +task :bump, [:version] do |t, args| + version = args[:version] + unless version + puts %(Usage: rake "bump[version]") + next + end + + FileUtils.mv "ICInputAccessory.xcodeproj", "ICInputAccessory.tmp" + sh %(xcrun agvtool new-marketing-version #{version}) + FileUtils.mv "ICInputAccessory.tmp", "ICInputAccessory.xcodeproj" + + FileUtils.mv "Example.xcodeproj", "Example.tmp" + sh %(xcrun agvtool new-marketing-version #{version}) + FileUtils.mv "Example.tmp", "Example.xcodeproj" + + podspec = "ICInputAccessory.podspec" + text = File.read podspec + File.write podspec, text.gsub(%r(\"\d+\.\d+\.\d+\"), "\"#{version}\"") + puts "Updated #{podspec} to #{version}" + + jazzy = ".jazzy.yml" + text = File.read jazzy + File.write jazzy, text.gsub(%r(:\s\d+\.\d+\.\d+), ": #{version}") + puts "Updated #{jazzy} to #{version}" + + sh %(bundle exec pod install) +end diff --git a/Source/KeyboardDismissTextField/ICKeyboardDismissAccessoryView.swift b/Source/KeyboardDismissTextField/ICKeyboardDismissAccessoryView.swift index 1b06b15..e6b8afa 100644 --- a/Source/KeyboardDismissTextField/ICKeyboardDismissAccessoryView.swift +++ b/Source/KeyboardDismissTextField/ICKeyboardDismissAccessoryView.swift @@ -28,7 +28,7 @@ import UIKit /// A customized keyboard accessory view with a dismiss button. @IBDesignable -public class ICKeyboardDismissAccessoryView: UIView { +open class ICKeyboardDismissAccessoryView: UIView { /// The background color of the button to dismiss keyboard. @IBInspectable public var buttonColor: UIColor = Constants.ButtonColor { @@ -40,14 +40,14 @@ public class ICKeyboardDismissAccessoryView: UIView { /// The button to dismiss keyboard. public private(set) lazy var dismissButton: UIButton = { let _button = UIButton() - let resources = NSBundle(forClass: self.dynamicType) - let icon = UIImage(named: "icook-iphone-button-hide-keyboard", inBundle: resources, compatibleWithTraitCollection: nil) - _button.setImage(icon, forState: .Normal) + let resources = Bundle(for: type(of: self)) + let icon = UIImage(named: "icook-iphone-button-hide-keyboard", in: resources, compatibleWith: nil) + _button.setImage(icon, for: UIControlState()) _button.backgroundColor = Constants.ButtonColor - _button.exclusiveTouch = true + _button.isExclusiveTouch = true _button.layer.cornerRadius = 4 _button.layer.shouldRasterize = true - _button.layer.rasterizationScale = UIScreen.mainScreen().scale + _button.layer.rasterizationScale = UIScreen.main.scale return _button }() @@ -73,11 +73,11 @@ public class ICKeyboardDismissAccessoryView: UIView { // MARK: - UIView - public override func pointInside(point: CGPoint, withEvent event: UIEvent?) -> Bool { + open override func point(inside point: CGPoint, with event: UIEvent?) -> Bool { for subview in subviews { - if !subview.hidden && subview.alpha > 0 && - subview.userInteractionEnabled && - subview.pointInside(convertPoint(point, toView: subview), withEvent: event) { + if !subview.isHidden && subview.alpha > 0 && + subview.isUserInteractionEnabled && + subview.point(inside: convert(point, to: subview), with: event) { return true } } @@ -86,8 +86,8 @@ public class ICKeyboardDismissAccessoryView: UIView { // MARK: - NSKeyValueCoding - public override func setValue(value: AnyObject?, forUndefinedKey key: String) { - if let color = value as? UIColor where key == "buttonColor" { + open override func setValue(_ value: Any?, forKey key: String) { + if let color = value as? UIColor, key == "buttonColor" { buttonColor = color } } @@ -95,7 +95,7 @@ public class ICKeyboardDismissAccessoryView: UIView { // MARK: - Private Methods private func setUpSubviews() { - backgroundColor = UIColor.clearColor() + backgroundColor = UIColor.clear addSubview(dismissButton) dismissButton.translatesAutoresizingMaskIntoConstraints = false @@ -107,14 +107,14 @@ public class ICKeyboardDismissAccessoryView: UIView { "padding": Constants.EdgePadding ] - addConstraints(NSLayoutConstraint.constraintsWithVisualFormat( - "H:[button(width)]-(padding)-|", + addConstraints(NSLayoutConstraint.constraints( + withVisualFormat: "H:[button(width)]-(padding)-|", options: [], metrics: metrics, views: views )) - addConstraints(NSLayoutConstraint.constraintsWithVisualFormat( - "V:[button(height)]-(padding)-|", + addConstraints(NSLayoutConstraint.constraints( + withVisualFormat: "V:[button(height)]-(padding)-|", options: [], metrics: metrics, views: views diff --git a/Source/KeyboardDismissTextField/ICKeyboardDismissTextField.swift b/Source/KeyboardDismissTextField/ICKeyboardDismissTextField.swift index aefea51..81980b3 100644 --- a/Source/KeyboardDismissTextField/ICKeyboardDismissTextField.swift +++ b/Source/KeyboardDismissTextField/ICKeyboardDismissTextField.swift @@ -28,13 +28,13 @@ import UIKit /// A text field that has a button to dismiss keyboard on the input accessory view. @IBDesignable -public class ICKeyboardDismissTextField: UITextField { +open class ICKeyboardDismissTextField: UITextField { /// The custom input accessory view with a button to dismiss keyboard. @IBOutlet public var keyboardAccessoryView: ICKeyboardDismissAccessoryView! { didSet { - if UI_USER_INTERFACE_IDIOM() != .Phone { return } - keyboardAccessoryView.dismissButton.addTarget(self, action: .dismiss, forControlEvents: .TouchUpInside) + if UI_USER_INTERFACE_IDIOM() != .phone { return } + keyboardAccessoryView.dismissButton.addTarget(self, action: .dismiss, for: .touchUpInside) inputAccessoryView = keyboardAccessoryView } } @@ -55,16 +55,16 @@ public class ICKeyboardDismissTextField: UITextField { // MARK: - UIResponder - public override func becomeFirstResponder() -> Bool { - if UI_USER_INTERFACE_IDIOM() == .Phone { + open override func becomeFirstResponder() -> Bool { + if UI_USER_INTERFACE_IDIOM() == .phone { keyboardAccessoryView.alpha = 1 } return super.becomeFirstResponder() } - @objc private func dismiss(sender: UIButton) { + @objc fileprivate func dismiss(_ sender: UIButton) { resignFirstResponder() - UIView.animateWithDuration(0.3) { + UIView.animate(withDuration: 0.3) { self.keyboardAccessoryView.alpha = 0 } } diff --git a/Source/TokenField/ICBackspaceTextField.swift b/Source/TokenField/ICBackspaceTextField.swift index 296d6ac..a83aa1f 100644 --- a/Source/TokenField/ICBackspaceTextField.swift +++ b/Source/TokenField/ICBackspaceTextField.swift @@ -27,7 +27,7 @@ import UIKit protocol ICBackspaceTextFieldDelegate: class { - func textFieldShouldDelete(textField: ICBackspaceTextField) -> Bool + func textFieldShouldDelete(_ textField: ICBackspaceTextField) -> Bool } //////////////////////////////////////////////////////////////////////////////// @@ -41,7 +41,7 @@ class ICBackspaceTextField: UITextField { didSet { // Trigger the lazy instantiation of cursorColor let color = cursorColor - tintColor = showsCursor ? color : UIColor.clearColor() + tintColor = showsCursor ? color : UIColor.clear } } @@ -49,14 +49,14 @@ class ICBackspaceTextField: UITextField { // MARK: - UIView - override func pointInside(point: CGPoint, withEvent event: UIEvent?) -> Bool { + override func point(inside point: CGPoint, with event: UIEvent?) -> Bool { // Forward touches to the superview when the cursor is hidden. - return showsCursor && super.pointInside(point, withEvent: event) + return showsCursor && super.point(inside: point, with: event) } // MARK: - UITextField - func keyboardInputShouldDelete(textField: UITextField) -> Bool { + func keyboardInputShouldDelete(_ textField: UITextField) -> Bool { return backspaceDelegate?.textFieldShouldDelete(self) ?? true } diff --git a/Source/TokenField/ICInsetLabel.swift b/Source/TokenField/ICInsetLabel.swift index 34edffb..a696e48 100644 --- a/Source/TokenField/ICInsetLabel.swift +++ b/Source/TokenField/ICInsetLabel.swift @@ -29,26 +29,26 @@ import UIKit class ICInsetLabel: UILabel { enum CornerRadius { - case Dynamic - case Constant(CGFloat) + case dynamic + case constant(CGFloat) } - var contentEdgeInsets = UIEdgeInsetsZero - var cornerRadius = CornerRadius.Constant(0) + var contentEdgeInsets = UIEdgeInsets.zero + var cornerRadius = CornerRadius.constant(0) - convenience init(contentEdgeInsets: UIEdgeInsets, cornerRadius: CornerRadius = .Constant(0)) { + convenience init(contentEdgeInsets: UIEdgeInsets, cornerRadius: CornerRadius = .constant(0)) { self.init(frame: CGRect.zero) self.contentEdgeInsets = contentEdgeInsets self.cornerRadius = cornerRadius switch cornerRadius { - case .Constant(let radius) where radius > 0: + case let .constant(radius) where radius > 0: layer.cornerRadius = radius fallthrough - case .Dynamic: + case .dynamic: layer.masksToBounds = true layer.shouldRasterize = true - layer.rasterizationScale = UIScreen.mainScreen().scale + layer.rasterizationScale = UIScreen.main.scale default: break } @@ -56,8 +56,8 @@ class ICInsetLabel: UILabel { // MARK: - UIView - override func intrinsicContentSize() -> CGSize { - let size = super.intrinsicContentSize() + override var intrinsicContentSize: CGSize { + let size = super.intrinsicContentSize return CGSize( width: contentEdgeInsets.left + size.width + contentEdgeInsets.right, height: contentEdgeInsets.top + size.height + contentEdgeInsets.bottom @@ -66,7 +66,7 @@ class ICInsetLabel: UILabel { override func layoutSubviews() { super.layoutSubviews() - if case .Dynamic = cornerRadius { + if case .dynamic = cornerRadius { layer.cornerRadius = frame.height / 2 } } diff --git a/Source/TokenField/ICToken.swift b/Source/TokenField/ICToken.swift index 6078169..10ff293 100644 --- a/Source/TokenField/ICToken.swift +++ b/Source/TokenField/ICToken.swift @@ -31,7 +31,7 @@ class ICToken: UIView { var text = "" { didSet { updateTextLabel() - frame = CGRect(origin: CGPoint.zero, size: systemLayoutSizeFittingSize(UILayoutFittingCompressedSize)) + frame = CGRect(origin: CGPoint.zero, size: systemLayoutSizeFitting(UILayoutFittingCompressedSize)) } } @@ -43,7 +43,7 @@ class ICToken: UIView { var normalTextAttributes: [String : NSObject] = [ NSForegroundColorAttributeName: UIColor(red:0.14, green:0.38, blue:0.95, alpha:1), - NSBackgroundColorAttributeName: UIColor.clearColor() + NSBackgroundColorAttributeName: UIColor.clear ] { didSet { if !highlighted { updateTextLabel() } @@ -52,7 +52,7 @@ class ICToken: UIView { } var highlightedTextAttributes: [String: NSObject] = [ - NSForegroundColorAttributeName: UIColor.whiteColor(), + NSForegroundColorAttributeName: UIColor.white, NSBackgroundColorAttributeName: UIColor(red:0.14, green:0.38, blue:0.95, alpha:1) ] { didSet { @@ -70,8 +70,8 @@ class ICToken: UIView { }() private(set) lazy var textLabel: UILabel = { - let _label = ICInsetLabel(contentEdgeInsets: UIEdgeInsets(top: 3, left: 5, bottom: 3, right: 5), cornerRadius: .Constant(3)) - _label.textAlignment = .Center + let _label = ICInsetLabel(contentEdgeInsets: UIEdgeInsets(top: 3, left: 5, bottom: 3, right: 5), cornerRadius: .constant(3)) + _label.textAlignment = .center _label.textColor = self.normalTextAttributes[NSForegroundColorAttributeName] as? UIColor _label.backgroundColor = self.normalTextAttributes[NSBackgroundColorAttributeName] as? UIColor _label.numberOfLines = 1 @@ -98,7 +98,7 @@ class ICToken: UIView { setText(text) } - private func setText(text: String) { + private func setText(_ text: String) { self.text = text } @@ -127,12 +127,12 @@ class ICToken: UIView { "text": textLabel, "delimiter": delimiterLabel ] - addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[text][delimiter]|", - options: [.AlignAllCenterY], + addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|[text][delimiter]|", + options: [.alignAllCenterY], metrics: nil, views: views )) - addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-2-[text]-2-|", + addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|-2-[text]-2-|", options: [], metrics: nil, views: views diff --git a/Source/TokenField/ICTokenField.swift b/Source/TokenField/ICTokenField.swift index 6d52e54..eeed91c 100644 --- a/Source/TokenField/ICTokenField.swift +++ b/Source/TokenField/ICTokenField.swift @@ -29,21 +29,21 @@ import UIKit /// The protocol defines the messages sent to a delegate. All the methods are optional. @objc public protocol ICTokenFieldDelegate: NSObjectProtocol { /// Tells the delegate that editing began for the token field. - optional func tokenFieldDidBeginEditing(tokenField: ICTokenField) + @objc optional func tokenFieldDidBeginEditing(_ tokenField: ICTokenField) /// Tells the delegate that editing stopped for the token field. - optional func tokenFieldDidEndEditing(tokenField: ICTokenField) + @objc optional func tokenFieldDidEndEditing(_ tokenField: ICTokenField) /// Tells the delegate that the token field will process the pressing of the return button. - optional func tokenFieldWillReturn(tokenField: ICTokenField) + @objc optional func tokenFieldWillReturn(_ tokenField: ICTokenField) /// Tells the delegate that the text becomes a token in the token field. - optional func tokenField(tokenField: ICTokenField, didEnterText text: String) + @objc optional func tokenField(_ tokenField: ICTokenField, didEnterText text: String) /// Tells the delegate that the token at certain index is removed from the token field. - optional func tokenField(tokenField: ICTokenField, didDeleteText text: String, atIndex index: Int) + @objc optional func tokenField(_ tokenField: ICTokenField, didDeleteText text: String, atIndex index: Int) } /// A text field that groups input texts with delimiters. @IBDesignable -public class ICTokenField: UIView, UITextFieldDelegate, ICBackspaceTextFieldDelegate { +open class ICTokenField: UIView, UITextFieldDelegate, ICBackspaceTextFieldDelegate { // MARK: - Public Properties @@ -63,7 +63,7 @@ public class ICTokenField: UIView, UITextFieldDelegate, ICBackspaceTextFieldDele didSet { if let icon = icon { let imageView = UIImageView(image: icon) - imageView.contentMode = .Center + imageView.contentMode = .center leftView = imageView } else { leftView = nil @@ -108,10 +108,10 @@ public class ICTokenField: UIView, UITextFieldDelegate, ICBackspaceTextFieldDele if placeholderLabel.superview != nil { return } insertSubview(placeholderLabel, belowSubview: scrollView) placeholderLabel.translatesAutoresizingMaskIntoConstraints = false - placeholderLabel.setContentHuggingPriority(UILayoutPriorityDefaultLow - 1, forAxis: .Horizontal) - addConstraint(NSLayoutConstraint(item: placeholderLabel, attribute: .Leading, relatedBy: .Equal, toItem: scrollView, attribute: .Leading, multiplier: 1, constant: 0)) - addConstraint(NSLayoutConstraint(item: placeholderLabel, attribute: .Trailing, relatedBy: .GreaterThanOrEqual, toItem: scrollView, attribute: .Trailing, multiplier: 1, constant: 10)) - addConstraint(NSLayoutConstraint(item: placeholderLabel, attribute: .CenterY, relatedBy: .Equal, toItem: self, attribute: .CenterY, multiplier: 1, constant: 0)) + placeholderLabel.setContentHuggingPriority(UILayoutPriorityDefaultLow - 1, for: .horizontal) + addConstraint(NSLayoutConstraint(item: placeholderLabel, attribute: .leading, relatedBy: .equal, toItem: scrollView, attribute: .leading, multiplier: 1, constant: 0)) + addConstraint(NSLayoutConstraint(item: placeholderLabel, attribute: .trailing, relatedBy: .greaterThanOrEqual, toItem: scrollView, attribute: .trailing, multiplier: 1, constant: 10)) + addConstraint(NSLayoutConstraint(item: placeholderLabel, attribute: .centerY, relatedBy: .equal, toItem: self, attribute: .centerY, multiplier: 1, constant: 0)) } } @@ -130,7 +130,7 @@ public class ICTokenField: UIView, UITextFieldDelegate, ICBackspaceTextFieldDele } /// The tint color of icon image and text field. - public override var tintColor: UIColor! { + open override var tintColor: UIColor! { didSet { inputTextField.tintColor = tintColor leftView?.tintColor = tintColor @@ -164,25 +164,25 @@ public class ICTokenField: UIView, UITextFieldDelegate, ICBackspaceTextFieldDele private lazy var inputTextField: ICBackspaceTextField = { let _textField = ICBackspaceTextField() - _textField.backgroundColor = UIColor.clearColor() - _textField.clearButtonMode = .WhileEditing - _textField.autocorrectionType = .No - _textField.returnKeyType = .Search + _textField.backgroundColor = UIColor.clear + _textField.clearButtonMode = .whileEditing + _textField.autocorrectionType = .no + _textField.returnKeyType = .search _textField.delegate = self _textField.backspaceDelegate = self - _textField.addTarget(self, action: .togglePlaceholderIfNeeded, forControlEvents: .AllEditingEvents) + _textField.addTarget(self, action: .togglePlaceholderIfNeeded, for: .allEditingEvents) return _textField }() private var leftView: UIView? { didSet { oldValue?.removeFromSuperview() - leftEdgeConstraint.active = leftView == nil + leftEdgeConstraint.isActive = leftView == nil if let icon = leftView { addSubview(icon) icon.translatesAutoresizingMaskIntoConstraints = false - addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-10-[icon]-10-[wrapper]", options: [], metrics: nil, views: ["icon": icon, "wrapper": scrollView])) - addConstraint(NSLayoutConstraint(item: icon, attribute: .CenterY, relatedBy: .Equal, toItem: self, attribute: .CenterY, multiplier: 1, constant: 0)) + addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|-10-[icon]-10-[wrapper]", options: [], metrics: nil, views: ["icon": icon, "wrapper": scrollView])) + addConstraint(NSLayoutConstraint(item: icon, attribute: .centerY, relatedBy: .equal, toItem: self, attribute: .centerY, multiplier: 1, constant: 0)) } } } @@ -192,15 +192,15 @@ public class ICTokenField: UIView, UITextFieldDelegate, ICBackspaceTextFieldDele private lazy var scrollView: UIScrollView = { let _scrollView = UIScrollView() _scrollView.clipsToBounds = true - _scrollView.directionalLockEnabled = true + _scrollView.isDirectionalLockEnabled = true _scrollView.showsHorizontalScrollIndicator = false _scrollView.showsVerticalScrollIndicator = false - _scrollView.backgroundColor = UIColor.clearColor() + _scrollView.backgroundColor = UIColor.clear return _scrollView }() private lazy var leftEdgeConstraint: NSLayoutConstraint = { - NSLayoutConstraint(item: self.scrollView, attribute: .Left, relatedBy: .Equal, toItem: self, attribute: .Left, multiplier: 1, constant: 10) + NSLayoutConstraint(item: self.scrollView, attribute: .left, relatedBy: .equal, toItem: self, attribute: .left, multiplier: 1, constant: 10) }() private lazy var tapGestureRecognizer: UITapGestureRecognizer = { @@ -223,29 +223,29 @@ public class ICTokenField: UIView, UITextFieldDelegate, ICBackspaceTextFieldDele // MARK: - UIResponder - public override func isFirstResponder() -> Bool { - return inputTextField.isFirstResponder() || super.isFirstResponder() + open override var isFirstResponder: Bool { + return inputTextField.isFirstResponder || super.isFirstResponder } - public override func becomeFirstResponder() -> Bool { + open override func becomeFirstResponder() -> Bool { return inputTextField.becomeFirstResponder() } - public override func resignFirstResponder() -> Bool { + open override func resignFirstResponder() -> Bool { super.resignFirstResponder() return inputTextField.resignFirstResponder() } // MARK: - UIView - public override func layoutSubviews() { + open override func layoutSubviews() { super.layoutSubviews() layoutTokenTextField() } // MARK: - NSKeyValueCoding - public override func setValue(value: AnyObject?, forUndefinedKey key: String) { + open override func setValue(_ value: Any?, forKey key: String) { switch value { case let image as UIImage? where key == "icon": icon = image @@ -262,40 +262,39 @@ public class ICTokenField: UIView, UITextFieldDelegate, ICBackspaceTextFieldDele // MARK: - UITextFieldDelegate - public func textFieldShouldBeginEditing(textField: UITextField) -> Bool { + open func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool { tokens.forEach { $0.highlighted = false } return true } - public func textFieldDidBeginEditing(textField: UITextField) { + open func textFieldDidBeginEditing(_ textField: UITextField) { delegate?.tokenFieldDidBeginEditing?(self) } - public func textFieldDidEndEditing(textField: UITextField) { + open func textFieldDidEndEditing(_ textField: UITextField) { completeCurrentInputText() togglePlaceholderIfNeeded() tokens.forEach { $0.highlighted = false } delegate?.tokenFieldDidEndEditing?(self) } - public func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool { - removeHighlightedToken() // as user starts typing when a token is focused + open func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { + _ = removeHighlightedToken() // as user starts typing when a token is focused inputTextField.showsCursor = true - guard let - input = textField.text, - text: NSString = (input as NSString).stringByReplacingCharactersInRange(range, withString: string) - else { + guard let input = textField.text else { return true } - for delimiter in delimiters as [NSString] { - let index = text.length - delimiter.length - if 0 < index && text.substringFromIndex(index) == delimiter { - let newToken = text.substringToIndex(index) + let text = (input as NSString).replacingCharacters(in: range, with: string) + + for delimiter in delimiters { + if text.hasSuffix(delimiter) { + let index = text.index(text.endIndex, offsetBy: -delimiter.characters.count) + let newToken = text.substring(to: index) textField.text = nil - if newToken != delimiter { + if !newToken.isEmpty && newToken != delimiter { tokens.append(ICToken(text: newToken, normalAttributes: normalTokenAttributes, highlightedAttributes: highlightedTokenAttributes)) layoutTokenTextField() delegate?.tokenField?(self, didEnterText: newToken) @@ -308,7 +307,7 @@ public class ICTokenField: UIView, UITextFieldDelegate, ICBackspaceTextFieldDele return true } - public func textFieldShouldReturn(textField: UITextField) -> Bool { + open func textFieldShouldReturn(_ textField: UITextField) -> Bool { completeCurrentInputText() togglePlaceholderIfNeeded() delegate?.tokenFieldWillReturn?(self) @@ -317,17 +316,17 @@ public class ICTokenField: UIView, UITextFieldDelegate, ICBackspaceTextFieldDele // MARK: - ICBackspaceTextFieldDelegate - func textFieldShouldDelete(textField: ICBackspaceTextField) -> Bool { + func textFieldShouldDelete(_ textField: ICBackspaceTextField) -> Bool { if tokens.isEmpty { return true } if !textField.showsCursor { - removeHighlightedToken() + _ = removeHighlightedToken() return true } - if let text = textField.text where text.isEmpty { + if let text = textField.text, text.isEmpty { textField.showsCursor = false tokens.last?.highlighted = true } @@ -336,17 +335,17 @@ public class ICTokenField: UIView, UITextFieldDelegate, ICBackspaceTextFieldDele // MARK: - UIResponder Callbacks - @objc private func togglePlaceholderIfNeeded(sender: UITextField? = nil) { + @objc fileprivate func togglePlaceholderIfNeeded(_ sender: UITextField? = nil) { let showsPlaceholder = tokens.isEmpty && (inputTextField.text?.isEmpty ?? true) - placeholderLabel.hidden = !showsPlaceholder + placeholderLabel.isHidden = !showsPlaceholder } - @objc private func handleTapGesture(sender: UITapGestureRecognizer) { - if !isFirstResponder() { + @objc fileprivate func handleTapGesture(_ sender: UITapGestureRecognizer) { + if !isFirstResponder { inputTextField.becomeFirstResponder() } - let touch = sender.locationInView(scrollView) + let touch = sender.location(in: scrollView) var shouldFocusInputTextField = true // Hilight the tapped token @@ -367,9 +366,9 @@ public class ICTokenField: UIView, UITextFieldDelegate, ICBackspaceTextFieldDele /// Returns true if any highlighted token is found and removed, otherwise false. private func removeHighlightedToken() -> Bool { - for (index, token) in tokens.enumerate() { + for (index, token) in tokens.enumerated() { if token.highlighted { - tokens.removeAtIndex(index) + tokens.remove(at: index) layoutTokenTextField() togglePlaceholderIfNeeded() inputTextField.showsCursor = true @@ -381,8 +380,8 @@ public class ICTokenField: UIView, UITextFieldDelegate, ICBackspaceTextFieldDele } private func setUpSubviews() { - if CGRectEqualToRect(frame, CGRect.zero) { - frame = CGRect(x: 0, y: 7, width: UIScreen.mainScreen().bounds.width, height: 30) + if frame.equalTo(CGRect.zero) { + frame = CGRect(x: 0, y: 7, width: UIScreen.main.bounds.width, height: 30) } addSubview(scrollView) @@ -390,9 +389,9 @@ public class ICTokenField: UIView, UITextFieldDelegate, ICBackspaceTextFieldDele scrollView.translatesAutoresizingMaskIntoConstraints = false let views = ["wrapper": scrollView] - addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-(>=10)-[wrapper]|", options: [], metrics: nil, views: views)) - addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|[wrapper]|", options: [], metrics: nil, views: views)) - leftEdgeConstraint.active = true + addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|-(>=10)-[wrapper]|", options: [], metrics: nil, views: views)) + addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|[wrapper]|", options: [], metrics: nil, views: views)) + leftEdgeConstraint.isActive = true layoutTokenTextField() addGestureRecognizer(tapGestureRecognizer) @@ -433,8 +432,8 @@ public class ICTokenField: UIView, UITextFieldDelegate, ICBackspaceTextFieldDele // MARK: - Public Methods /// Creates a token with the current input text. - public func completeCurrentInputText() { - guard let text = inputTextField.text where !text.isEmpty else { + open func completeCurrentInputText() { + guard let text = inputTextField.text, !text.isEmpty else { return } inputTextField.text = nil @@ -444,7 +443,7 @@ public class ICTokenField: UIView, UITextFieldDelegate, ICBackspaceTextFieldDele } /// Removes the input text and all displayed tokens. - public func resetTokens() { + open func resetTokens() { inputTextField.text = nil tokens.removeAll() layoutTokenTextField() diff --git a/scripts/swiftlint.sh b/scripts/swiftlint.sh new file mode 100644 index 0000000..2697cd1 --- /dev/null +++ b/scripts/swiftlint.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +if ! command -v swiftlint >/dev/null; then + brew install swiftlint +elif [ ! -e .swiftlint-version ] || [ $(swiftlint version) != $(head -n 1 .swiftlint-version) ]; then + brew upgrade swiftlint + swiftlint version >> .swiftlint-version +fi + +swiftlint diff --git a/scripts/update-docs.sh b/scripts/update-docs.sh new file mode 100644 index 0000000..28a174b --- /dev/null +++ b/scripts/update-docs.sh @@ -0,0 +1,29 @@ +#!/bin/sh + +files=(html css js json) + +for file in "${files[@]}" +do + echo "Cleaning whitespace in *.$file..." + find docs/output -name "*."$file -exec sed -E -i '' -e 's/[[:blank:]]*$//' {} \; +done + + +cd docs && pwd +git checkout gh-pages +git status +cp -rfv output/* . +git --no-pager diff --stat +git add . +git commit -m "[CI] Update documentation at $(date +'%Y-%m-%d %H:%M:%S %z')" + +if [ "${TRAVIS_BRANCH}" = "master" ] && [ -n "$DANGER_GITHUB_API_TOKEN" ]; then + echo "Updating gh-pages..." + git remote add upstream "https://${DANGER_GITHUB_API_TOKEN}@github.com/polydice/ICInputAccessory.git" + git push --quiet upstream HEAD:gh-pages + git remote remove upstream +else + echo "Skip gh-pages updates on ${TRAVIS_BRANCH}" +fi + +cd -