Skip to content

Commit 0e2b45a

Browse files
authored
Swift 4 Fix (#19)
* Update to Swift 4 * Add UIGestureRecognizerDelegate * Bump pod version 🚀 * Update travis-ci
1 parent 9fdac4a commit 0e2b45a

10 files changed

Lines changed: 65 additions & 25 deletions

File tree

.swift-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
4.0

.swiftlint.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,9 @@ line_length: 200
22
cyclomatic_complexity: 5
33
file_length:
44
warning: 500
5-
error: 1200
5+
error: 1000
6+
type_body_length:
7+
- 300 # warning
8+
- 400 # error
9+
disabled_rules: # rule identifiers to exclude from running
10+
- superfluous_disable_command

.travis.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
osx_image: xcode8.3
1+
osx_image: xcode9
22
language: swift
33
# cache: cocoapods
44
# podfile: Example/Podfile
@@ -8,17 +8,18 @@ env:
88
- LC_CTYPE=en_US.UTF-8
99
- LANG=en_US.UTF-8
1010
matrix:
11-
- DESTINATION="OS=10.3.1,name=iPhone 7 Plus" SDK="iphonesimulator10.3" POD_LINT="YES" SWIFT_LINT="YES"
12-
- DESTINATION="OS=9.0,name=iPhone 6" SDK="iphonesimulator10.3" POD_LINT="NO" SWIFT_LINT="NO"
13-
- DESTINATION="OS=8.1,name=iPhone 4S" SDK="iphonesimulator10.3" POD_LINT="NO" SWIFT_LINT="NO"
11+
- DESTINATION="OS=11.0,name=iPhone 8" SDK="iphonesimulator11.0" POD_LINT="YES" SWIFT_LINT="YES"
12+
- DESTINATION="OS=10.3.1,name=iPhone 7 Plus" SDK="iphonesimulator11.0" POD_LINT="NO" SWIFT_LINT="NO"
13+
- DESTINATION="OS=9.3,name=iPhone 6" SDK="iphonesimulator11.0" POD_LINT="NO" SWIFT_LINT="NO"
14+
- DESTINATION="OS=8.4,name=iPhone 4S" SDK="iphonesimulator11.0" POD_LINT="NO" SWIFT_LINT="NO"
1415

1516
before_install:
1617
- brew install swiftlint
1718
- pod install --project-directory=Example
1819
# - gem install cocoapods # Since Travis is not always on latest version
20+
# - xcodebuild -showsdks
1921
# - instruments -s devices
2022
# - xcodebuild -version
21-
# - xcodebuild -showsdks
2223
# - xcodebuild -list
2324

2425
script:

Example/McPicker.xcodeproj/project.pbxproj

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -214,16 +214,16 @@
214214
isa = PBXProject;
215215
attributes = {
216216
LastSwiftUpdateCheck = 0720;
217-
LastUpgradeCheck = 0830;
217+
LastUpgradeCheck = 0900;
218218
ORGANIZATIONNAME = CocoaPods;
219219
TargetAttributes = {
220220
607FACCF1AFB9204008FA782 = {
221221
CreatedOnToolsVersion = 6.3.1;
222-
LastSwiftMigration = 0820;
222+
LastSwiftMigration = 0900;
223223
};
224224
607FACE41AFB9204008FA782 = {
225225
CreatedOnToolsVersion = 6.3.1;
226-
LastSwiftMigration = 0820;
226+
LastSwiftMigration = 0900;
227227
TestTargetID = 607FACCF1AFB9204008FA782;
228228
};
229229
};
@@ -430,14 +430,20 @@
430430
CLANG_CXX_LIBRARY = "libc++";
431431
CLANG_ENABLE_MODULES = YES;
432432
CLANG_ENABLE_OBJC_ARC = YES;
433+
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
433434
CLANG_WARN_BOOL_CONVERSION = YES;
435+
CLANG_WARN_COMMA = YES;
434436
CLANG_WARN_CONSTANT_CONVERSION = YES;
435437
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
436438
CLANG_WARN_EMPTY_BODY = YES;
437439
CLANG_WARN_ENUM_CONVERSION = YES;
438440
CLANG_WARN_INFINITE_RECURSION = YES;
439441
CLANG_WARN_INT_CONVERSION = YES;
442+
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
443+
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
440444
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
445+
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
446+
CLANG_WARN_STRICT_PROTOTYPES = YES;
441447
CLANG_WARN_SUSPICIOUS_MOVE = YES;
442448
CLANG_WARN_UNREACHABLE_CODE = YES;
443449
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
@@ -477,14 +483,20 @@
477483
CLANG_CXX_LIBRARY = "libc++";
478484
CLANG_ENABLE_MODULES = YES;
479485
CLANG_ENABLE_OBJC_ARC = YES;
486+
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
480487
CLANG_WARN_BOOL_CONVERSION = YES;
488+
CLANG_WARN_COMMA = YES;
481489
CLANG_WARN_CONSTANT_CONVERSION = YES;
482490
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
483491
CLANG_WARN_EMPTY_BODY = YES;
484492
CLANG_WARN_ENUM_CONVERSION = YES;
485493
CLANG_WARN_INFINITE_RECURSION = YES;
486494
CLANG_WARN_INT_CONVERSION = YES;
495+
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
496+
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
487497
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
498+
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
499+
CLANG_WARN_STRICT_PROTOTYPES = YES;
488500
CLANG_WARN_SUSPICIOUS_MOVE = YES;
489501
CLANG_WARN_UNREACHABLE_CODE = YES;
490502
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
@@ -522,7 +534,8 @@
522534
MODULE_NAME = ExampleApp;
523535
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
524536
PRODUCT_NAME = "$(TARGET_NAME)";
525-
SWIFT_VERSION = 3.0;
537+
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
538+
SWIFT_VERSION = 4.0;
526539
TARGETED_DEVICE_FAMILY = "1,2";
527540
};
528541
name = Debug;
@@ -540,7 +553,8 @@
540553
MODULE_NAME = ExampleApp;
541554
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
542555
PRODUCT_NAME = "$(TARGET_NAME)";
543-
SWIFT_VERSION = 3.0;
556+
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
557+
SWIFT_VERSION = 4.0;
544558
TARGETED_DEVICE_FAMILY = "1,2";
545559
};
546560
name = Release;
@@ -558,7 +572,8 @@
558572
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
559573
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)";
560574
PRODUCT_NAME = "$(TARGET_NAME)";
561-
SWIFT_VERSION = 3.0;
575+
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
576+
SWIFT_VERSION = 4.0;
562577
};
563578
name = Debug;
564579
};
@@ -571,7 +586,8 @@
571586
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
572587
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)";
573588
PRODUCT_NAME = "$(TARGET_NAME)";
574-
SWIFT_VERSION = 3.0;
589+
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
590+
SWIFT_VERSION = 4.0;
575591
};
576592
name = Release;
577593
};

Example/McPicker.xcodeproj/xcshareddata/xcschemes/McPicker-Example.xcscheme

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0830"
3+
LastUpgradeVersion = "0900"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -40,6 +40,7 @@
4040
buildConfiguration = "Debug"
4141
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
4242
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
43+
language = ""
4344
shouldUseLaunchSchemeArgsEnv = "YES">
4445
<Testables>
4546
<TestableReference
@@ -69,6 +70,7 @@
6970
buildConfiguration = "Debug"
7071
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
7172
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
73+
language = ""
7274
launchStyle = "0"
7375
useCustomWorkingDirectory = "NO"
7476
ignoresPersistentStateOnLaunch = "NO"

Example/McPicker.xcodeproj/xcshareddata/xcschemes/McPicker_Tests.xcscheme

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0830"
3+
LastUpgradeVersion = "0900"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -10,6 +10,7 @@
1010
buildConfiguration = "Debug"
1111
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
1212
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
13+
language = ""
1314
shouldUseLaunchSchemeArgsEnv = "YES">
1415
<Testables>
1516
<TestableReference
@@ -30,6 +31,7 @@
3031
buildConfiguration = "Debug"
3132
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
3233
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
34+
language = ""
3335
launchStyle = "0"
3436
useCustomWorkingDirectory = "NO"
3537
ignoresPersistentStateOnLaunch = "NO"

Example/Tests/McPickerTests.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class McPickerTests: XCTestCase {
5353
XCTAssertEqual(data[0][1], mcPicker.pickerData[0][1])
5454

5555
XCTAssertEqual(1, mcPicker.gestureRecognizers?.count)
56+
XCTAssertEqual(mcPicker, mcPicker.gestureRecognizers!.first!.delegate! as! TestMcPicker)
5657
XCTAssertEqual(5, mcPicker.toolbar.items?.count)
5758

5859
let fixedSpace = mcPicker.toolbar.items?[0] as! McPickerBarButtonItem
@@ -168,8 +169,8 @@ class McPickerTests: XCTestCase {
168169

169170
// Then
170171
//
171-
XCTAssertEqual(expectedFont, cancelBarButton.titleTextAttributes(for: .normal)?[NSFontAttributeName] as! UIFont)
172-
XCTAssertEqual(expectedFont, doneBarButton.titleTextAttributes(for: .normal)?[NSFontAttributeName] as! UIFont)
172+
XCTAssertEqual(expectedFont, cancelBarButton.titleTextAttributes(for: .normal)?[NSAttributedStringKey.font.rawValue] as! UIFont)
173+
XCTAssertEqual(expectedFont, doneBarButton.titleTextAttributes(for: .normal)?[NSAttributedStringKey.font.rawValue] as! UIFont)
173174
}
174175

175176
func testSetPickerBackgroundColor() {
@@ -205,7 +206,7 @@ class McPickerTests: XCTestCase {
205206

206207
// When
207208
//
208-
mcPicker.show(cancelHandler: {}) { (_: [Int : String]) in }
209+
mcPicker.show(cancelHandler: {}, doneHandler: { (_: [Int : String]) in })
209210
XCTAssertFalse(mcPicker.isPopoverMode)
210211
XCTAssertEqual(McPicker.AnimationDirection.in, mcPicker.direction)
211212
mcPicker.dismissViews()

McPicker.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'McPicker'
3-
s.version = '0.5.0'
3+
s.version = '0.5.1'
44
s.summary = 'McPicker is a UIPickerView drop-in solution with animations that is rotation ready.'
55

66
s.description = <<-DESC

McPicker/Classes/McPicker.swift

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ open class McPicker: UIView {
6767
public var toolbarItemsFont: UIFont? {
6868
didSet {
6969
applyToolbarButtonItemsSettings { (barButtonItem) in
70-
barButtonItem.setTitleTextAttributes([NSFontAttributeName: toolbarItemsFont!], for: .normal)
70+
barButtonItem.setTitleTextAttributes([.font: toolbarItemsFont!], for: .normal)
7171
}
7272
}
7373
}
@@ -112,7 +112,7 @@ open class McPicker: UIView {
112112
}
113113

114114
fileprivate var doneHandler:(_ selections: [Int:String]) -> Void = {_ in }
115-
fileprivate var cancelHandler:() -> Void = {_ in }
115+
fileprivate var cancelHandler:() -> Void = { }
116116

117117
private var appWindow: UIWindow {
118118
guard let window = UIApplication.shared.keyWindow else {
@@ -247,13 +247,13 @@ open class McPicker: UIView {
247247
super.willMove(toWindow: newWindow)
248248

249249
if newWindow != nil {
250-
NotificationCenter.default.addObserver(self, selector: #selector(sizeViews), name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)
250+
NotificationCenter.default.addObserver(self, selector: #selector(McPicker.sizeViews), name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)
251251
} else {
252252
NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)
253253
}
254254
}
255255

256-
internal func sizeViews() {
256+
@objc internal func sizeViews() {
257257
let size = isPopoverMode ? popOverContentSize : self.appWindow.bounds.size
258258
self.frame = CGRect(x: 0, y: 0, width: size.width, height: size.height)
259259

@@ -327,7 +327,9 @@ open class McPicker: UIView {
327327
}
328328

329329
private func setup() {
330-
self.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(cancel)))
330+
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(McPicker.cancel))
331+
tapGestureRecognizer.delegate = self
332+
self.addGestureRecognizer(tapGestureRecognizer)
331333

332334
let fixedSpace = McPickerBarButtonItem.fixedSpace(width: appWindow.bounds.size.width * Constant.barButtonFixedSpacePadding)
333335
setToolbarItems(items: [fixedSpace, McPickerBarButtonItem.cancel(mcPicker: self),
@@ -416,3 +418,13 @@ extension McPicker : UIPopoverPresentationControllerDelegate {
416418
return .none
417419
}
418420
}
421+
422+
extension McPicker : UIGestureRecognizerDelegate {
423+
424+
public func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
425+
if let goodView = touch.view {
426+
return goodView == self
427+
}
428+
return false
429+
}
430+
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ McPicker's `doneHandler` passes back `selections: [Int : String]` as an argument
8888
## Requirements
8989
- iOS 8+
9090
- Swift 3+
91-
- Xcode 8
91+
- Xcode 8+
9292

9393
## Installation
9494

0 commit comments

Comments
 (0)