Skip to content
This repository was archived by the owner on Jan 16, 2026. It is now read-only.

Commit f4eac2b

Browse files
committed
[Swift] Add support for Swift 4.2
1 parent 62322e7 commit f4eac2b

File tree

8 files changed

+86
-21
lines changed

8 files changed

+86
-21
lines changed

.swift-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4.0
1+
4.2

SkyFloatingLabelTextField/SkyFloatingLabelTextField.xcodeproj/project.pbxproj

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@
326326
TargetAttributes = {
327327
F547D4AB1C3BEA8F0075A0C2 = {
328328
CreatedOnToolsVersion = 7.2;
329-
LastSwiftMigration = 0810;
329+
LastSwiftMigration = 1000;
330330
};
331331
F56289171C3BE3A20082D9A6 = {
332332
CreatedOnToolsVersion = 7.2;
@@ -403,7 +403,7 @@
403403
);
404404
runOnlyForDeploymentPostprocessing = 0;
405405
shellPath = /bin/sh;
406-
shellScript = "if which swiftlint >/dev/null; then\n cd .. && swiftlint lint --config .swiftlint.yml\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi";
406+
shellScript = "if which swiftlint >/dev/null; then\n cd .. && swiftlint lint --config .swiftlint.yml\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n";
407407
};
408408
/* End PBXShellScriptBuildPhase section */
409409

@@ -504,7 +504,8 @@
504504
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
505505
PRODUCT_BUNDLE_IDENTIFIER = net.skyscanner.SkyFloatingLabelTextFieldExample;
506506
PRODUCT_NAME = "$(TARGET_NAME)";
507-
SWIFT_VERSION = 3.0;
507+
SWIFT_SWIFT3_OBJC_INFERENCE = On;
508+
SWIFT_VERSION = 4.2;
508509
};
509510
name = Debug;
510511
};
@@ -517,7 +518,8 @@
517518
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
518519
PRODUCT_BUNDLE_IDENTIFIER = net.skyscanner.SkyFloatingLabelTextFieldExample;
519520
PRODUCT_NAME = "$(TARGET_NAME)";
520-
SWIFT_VERSION = 3.0;
521+
SWIFT_SWIFT3_OBJC_INFERENCE = On;
522+
SWIFT_VERSION = 4.2;
521523
};
522524
name = Release;
523525
};
@@ -568,6 +570,7 @@
568570
ONLY_ACTIVE_ARCH = YES;
569571
SDKROOT = iphoneos;
570572
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
573+
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
571574
TARGETED_DEVICE_FAMILY = "1,2";
572575
VERSIONING_SYSTEM = "apple-generic";
573576
VERSION_INFO_PREFIX = "";
@@ -614,6 +617,7 @@
614617
MTL_ENABLE_DEBUG_INFO = NO;
615618
SDKROOT = iphoneos;
616619
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
620+
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
617621
TARGETED_DEVICE_FAMILY = "1,2";
618622
VALIDATE_PRODUCT = YES;
619623
VERSIONING_SYSTEM = "apple-generic";
@@ -637,7 +641,7 @@
637641
PRODUCT_NAME = "$(TARGET_NAME)";
638642
SKIP_INSTALL = YES;
639643
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
640-
SWIFT_VERSION = 4.0;
644+
SWIFT_VERSION = 4.2;
641645
};
642646
name = Debug;
643647
};
@@ -658,7 +662,7 @@
658662
PRODUCT_BUNDLE_IDENTIFIER = net.skyscanner.SkyFloatingLabelTextField;
659663
PRODUCT_NAME = "$(TARGET_NAME)";
660664
SKIP_INSTALL = YES;
661-
SWIFT_VERSION = 4.0;
665+
SWIFT_VERSION = 4.2;
662666
};
663667
name = Release;
664668
};
@@ -669,7 +673,7 @@
669673
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
670674
PRODUCT_BUNDLE_IDENTIFIER = net.skyscanner.SkyFloatingLabelTextFieldTests;
671675
PRODUCT_NAME = "$(TARGET_NAME)";
672-
SWIFT_VERSION = 4.0;
676+
SWIFT_VERSION = 4.2;
673677
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SkyFloatingLabelTextFieldExample.app/SkyFloatingLabelTextFieldExample";
674678
};
675679
name = Debug;
@@ -681,7 +685,7 @@
681685
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
682686
PRODUCT_BUNDLE_IDENTIFIER = net.skyscanner.SkyFloatingLabelTextFieldTests;
683687
PRODUCT_NAME = "$(TARGET_NAME)";
684-
SWIFT_VERSION = 4.0;
688+
SWIFT_VERSION = 4.2;
685689
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SkyFloatingLabelTextFieldExample.app/SkyFloatingLabelTextFieldExample";
686690
};
687691
name = Release;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>

SkyFloatingLabelTextField/SkyFloatingLabelTextFieldExample/AppDelegate.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,20 @@
1313

1414
import UIKit
1515

16+
#if swift(>=4.2)
17+
typealias LaunchOptionsKey = UIApplication.LaunchOptionsKey
18+
#else
19+
typealias LaunchOptionsKey = UIApplicationLaunchOptionsKey
20+
#endif
21+
1622
@UIApplicationMain
1723
class AppDelegate: UIResponder, UIApplicationDelegate {
1824

1925
var window: UIWindow?
2026

2127
func application(
2228
_ application: UIApplication,
23-
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?
29+
didFinishLaunchingWithOptions launchOptions: [LaunchOptionsKey: Any]?
2430
) -> Bool {
2531

2632
// MARK: - Appearance

SkyFloatingLabelTextField/SkyFloatingLabelTextFieldExample/Example0/ShowcaseExampleViewController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ class ShowcaseExampleViewController: UIViewController, UITextFieldDelegate {
245245

246246
// When pressing return, move to the next field
247247
let nextTag = textField.tag + 1
248-
if let nextResponder = textField.superview?.viewWithTag(nextTag) as UIResponder! {
248+
if let nextResponder = textField.superview?.viewWithTag(nextTag) {
249249
nextResponder.becomeFirstResponder()
250250
} else {
251251
textField.resignFirstResponder()
@@ -263,7 +263,7 @@ class ShowcaseExampleViewController: UIViewController, UITextFieldDelegate {
263263
return
264264
}
265265

266-
if email.characters.isEmpty {
266+
if email.isEmpty {
267267
emailField.errorMessage = nil
268268
} else if !validateEmail(email) {
269269
emailField.errorMessage = NSLocalizedString(

SkyFloatingLabelTextField/SkyFloatingLabelTextFieldExample/Example2/CustomizingColorsViewController.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,17 @@ class CustomizingColorsViewController: UIViewController {
3535
// NOTE: For emojis to appear properly we need to set the color to white
3636
// http://stackoverflow.com/a/38195951
3737

38-
var attributes: [String: Any] = [:]
38+
#if swift(>=4.2)
39+
var attributes: [NSAttributedString.Key: Any] = [:]
40+
#else
41+
var attributes: [String: Any] = [:]
42+
#endif
3943

40-
#if swift(>=4.0)
44+
#if swift(>=4.2) // Swift 4.2
45+
attributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
46+
#elseif swift(>=4.0) // Swift 4.0 and 4.1
4147
attributes = [NSAttributedStringKey.foregroundColor.rawValue: UIColor.white]
42-
#else
48+
#else // Swift 3 and earlier
4349
attributes = [NSForegroundColorAttributeName: UIColor.white]
4450
#endif
4551

SkyFloatingLabelTextField/SkyFloatingLabelTextFieldTests/SkyFloatingLabelTextFieldTests.swift

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,14 @@ class SkyFloatingLabelTextFieldTests: XCTestCase { // swiftlint:disable:this typ
5959
floatingLabelTextField.placeholderColor = customColor
6060

6161
// then
62-
#if swift(>=4.0)
62+
#if swift(>=4.2)
63+
XCTAssertEqual(
64+
floatingLabelTextField.attributedPlaceholder!.attribute(
65+
NSAttributedString.Key.foregroundColor, at: 0, effectiveRange: &fullRange
66+
) as? UIColor,
67+
customColor
68+
)
69+
#elseif swift(>=4.0)
6370
XCTAssertEqual(
6471
floatingLabelTextField.attributedPlaceholder!.attribute(
6572
NSAttributedStringKey.foregroundColor, at: 0, effectiveRange: &fullRange
@@ -213,7 +220,14 @@ class SkyFloatingLabelTextFieldTests: XCTestCase { // swiftlint:disable:this typ
213220
floatingLabelTextField.disabledColor = self.customColor
214221

215222
// then
216-
#if swift(>=4.0)
223+
#if swift(>=4.2)
224+
XCTAssertNotEqual(
225+
floatingLabelTextField.attributedPlaceholder!.attribute(
226+
NSAttributedString.Key.foregroundColor, at: 0, effectiveRange: &fullRange
227+
) as? UIColor,
228+
customColor
229+
)
230+
#elseif swift(>=4.0)
217231
XCTAssertNotEqual(
218232
floatingLabelTextField.attributedPlaceholder!.attribute(
219233
NSAttributedStringKey.foregroundColor, at: 0, effectiveRange: &fullRange
@@ -263,7 +277,14 @@ class SkyFloatingLabelTextFieldTests: XCTestCase { // swiftlint:disable:this typ
263277
floatingLabelTextField.disabledColor = self.customColor
264278

265279
// then
266-
#if swift(>=4.0)
280+
#if swift(>=4.2)
281+
XCTAssertEqual(
282+
floatingLabelTextField.attributedPlaceholder!.attribute(
283+
NSAttributedString.Key.foregroundColor, at: 0, effectiveRange: &fullRange
284+
) as? UIColor,
285+
customColor
286+
)
287+
#elseif swift(>=4.0)
267288
XCTAssertEqual(
268289
floatingLabelTextField.attributedPlaceholder!.attribute(
269290
NSAttributedStringKey.foregroundColor, at: 0, effectiveRange: &fullRange
@@ -304,7 +325,16 @@ class SkyFloatingLabelTextFieldTests: XCTestCase { // swiftlint:disable:this typ
304325
floatingLabelTextField.placeholderFont = customFont
305326

306327
// then
307-
#if swift(>=4.0)
328+
#if swift(>=4.2)
329+
XCTAssertEqual(
330+
floatingLabelTextField.attributedPlaceholder!.attribute(
331+
NSAttributedString.Key.font,
332+
at: 0,
333+
effectiveRange: &fullRange
334+
) as? UIFont,
335+
customFont
336+
)
337+
#elseif swift(>=4.0)
308338
XCTAssertEqual(
309339
floatingLabelTextField.attributedPlaceholder!.attribute(
310340
NSAttributedStringKey.font,

Sources/SkyFloatingLabelTextField.swift

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,14 @@ open class SkyFloatingLabelTextField: UITextField { // swiftlint:disable:this ty
7878
return
7979
}
8080
let color = isEnabled ? placeholderColor : disabledColor
81-
#if swift(>=4.0)
81+
#if swift(>=4.2)
82+
attributedPlaceholder = NSAttributedString(
83+
string: placeholder,
84+
attributes: [
85+
NSAttributedString.Key.foregroundColor: color, NSAttributedString.Key.font: font
86+
]
87+
)
88+
#elseif swift(>=4.0)
8289
attributedPlaceholder = NSAttributedString(
8390
string: placeholder,
8491
attributes: [
@@ -531,7 +538,11 @@ open class SkyFloatingLabelTextField: UITextField { // swiftlint:disable:this ty
531538
self.titleLabel.frame = frame
532539
}
533540
if animated {
534-
let animationOptions: UIViewAnimationOptions = .curveEaseOut
541+
#if swift(>=4.2)
542+
let animationOptions: UIView.AnimationOptions = .curveEaseOut
543+
#else
544+
let animationOptions: UIViewAnimationOptions = .curveEaseOut
545+
#endif
535546
let duration = isTitleVisible() ? titleFadeInDuration : titleFadeOutDuration
536547
UIView.animate(withDuration: duration, delay: 0, options: animationOptions, animations: { () -> Void in
537548
updateBlock()

0 commit comments

Comments
 (0)