diff --git a/.swift-version b/.swift-version new file mode 100644 index 0000000..5186d07 --- /dev/null +++ b/.swift-version @@ -0,0 +1 @@ +4.0 diff --git a/.swiftlint.yml b/.swiftlint.yml index 256e35a..8082319 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -2,4 +2,9 @@ line_length: 200 cyclomatic_complexity: 5 file_length: warning: 500 - error: 1200 + error: 1000 +type_body_length: + - 300 # warning + - 400 # error +disabled_rules: # rule identifiers to exclude from running + - superfluous_disable_command diff --git a/.travis.yml b/.travis.yml index 772519c..84b64d7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,4 @@ -osx_image: xcode8.3 +osx_image: xcode9 language: swift # cache: cocoapods # podfile: Example/Podfile @@ -8,17 +8,18 @@ env: - LC_CTYPE=en_US.UTF-8 - LANG=en_US.UTF-8 matrix: - - DESTINATION="OS=10.3.1,name=iPhone 7 Plus" SDK="iphonesimulator10.3" POD_LINT="YES" SWIFT_LINT="YES" - - DESTINATION="OS=9.0,name=iPhone 6" SDK="iphonesimulator10.3" POD_LINT="NO" SWIFT_LINT="NO" - - DESTINATION="OS=8.1,name=iPhone 4S" SDK="iphonesimulator10.3" POD_LINT="NO" SWIFT_LINT="NO" + - DESTINATION="OS=11.0,name=iPhone 8" SDK="iphonesimulator11.0" POD_LINT="YES" SWIFT_LINT="YES" + - DESTINATION="OS=10.3.1,name=iPhone 7 Plus" SDK="iphonesimulator11.0" POD_LINT="NO" SWIFT_LINT="NO" + - DESTINATION="OS=9.3,name=iPhone 6" SDK="iphonesimulator11.0" POD_LINT="NO" SWIFT_LINT="NO" + - DESTINATION="OS=8.4,name=iPhone 4S" SDK="iphonesimulator11.0" POD_LINT="NO" SWIFT_LINT="NO" before_install: - brew install swiftlint - pod install --project-directory=Example # - gem install cocoapods # Since Travis is not always on latest version + # - xcodebuild -showsdks # - instruments -s devices # - xcodebuild -version - # - xcodebuild -showsdks # - xcodebuild -list script: diff --git a/Example/McPicker.xcodeproj/project.pbxproj b/Example/McPicker.xcodeproj/project.pbxproj index b16bad6..7384ff3 100644 --- a/Example/McPicker.xcodeproj/project.pbxproj +++ b/Example/McPicker.xcodeproj/project.pbxproj @@ -214,16 +214,16 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0720; - LastUpgradeCheck = 0830; + LastUpgradeCheck = 0900; ORGANIZATIONNAME = CocoaPods; TargetAttributes = { 607FACCF1AFB9204008FA782 = { CreatedOnToolsVersion = 6.3.1; - LastSwiftMigration = 0820; + LastSwiftMigration = 0900; }; 607FACE41AFB9204008FA782 = { CreatedOnToolsVersion = 6.3.1; - LastSwiftMigration = 0820; + LastSwiftMigration = 0900; TestTargetID = 607FACCF1AFB9204008FA782; }; }; @@ -430,14 +430,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; @@ -477,14 +483,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; @@ -522,7 +534,8 @@ MODULE_NAME = ExampleApp; PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -540,7 +553,8 @@ MODULE_NAME = ExampleApp; PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; @@ -558,7 +572,8 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -571,7 +586,8 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.0; }; name = Release; }; diff --git a/Example/McPicker.xcodeproj/xcshareddata/xcschemes/McPicker-Example.xcscheme b/Example/McPicker.xcodeproj/xcshareddata/xcschemes/McPicker-Example.xcscheme index 786e594..559b961 100644 --- a/Example/McPicker.xcodeproj/xcshareddata/xcschemes/McPicker-Example.xcscheme +++ b/Example/McPicker.xcodeproj/xcshareddata/xcschemes/McPicker-Example.xcscheme @@ -1,6 +1,6 @@ Void = {_ in } - fileprivate var cancelHandler:() -> Void = {_ in } + fileprivate var cancelHandler:() -> Void = { } private var appWindow: UIWindow { guard let window = UIApplication.shared.keyWindow else { @@ -247,13 +247,13 @@ open class McPicker: UIView { super.willMove(toWindow: newWindow) if newWindow != nil { - NotificationCenter.default.addObserver(self, selector: #selector(sizeViews), name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(McPicker.sizeViews), name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil) } else { NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil) } } - internal func sizeViews() { + @objc internal func sizeViews() { let size = isPopoverMode ? popOverContentSize : self.appWindow.bounds.size self.frame = CGRect(x: 0, y: 0, width: size.width, height: size.height) @@ -327,7 +327,9 @@ open class McPicker: UIView { } private func setup() { - self.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(cancel))) + let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(McPicker.cancel)) + tapGestureRecognizer.delegate = self + self.addGestureRecognizer(tapGestureRecognizer) let fixedSpace = McPickerBarButtonItem.fixedSpace(width: appWindow.bounds.size.width * Constant.barButtonFixedSpacePadding) setToolbarItems(items: [fixedSpace, McPickerBarButtonItem.cancel(mcPicker: self), @@ -416,3 +418,13 @@ extension McPicker : UIPopoverPresentationControllerDelegate { return .none } } + +extension McPicker : UIGestureRecognizerDelegate { + + public func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool { + if let goodView = touch.view { + return goodView == self + } + return false + } +} diff --git a/README.md b/README.md index b1a6e27..6eac931 100644 --- a/README.md +++ b/README.md @@ -88,7 +88,7 @@ McPicker's `doneHandler` passes back `selections: [Int : String]` as an argument ## Requirements - iOS 8+ - Swift 3+ -- Xcode 8 +- Xcode 8+ ## Installation