Skip to content

Commit 9dc8536

Browse files
committed
Swift 4
1 parent a3d937f commit 9dc8536

12 files changed

+57
-32
lines changed

Spring/DesignableLabel.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ import UIKit
3333
paragraphStyle.lineSpacing = lineHeight
3434

3535
let attributedString = NSMutableAttributedString(string: text!)
36-
attributedString.addAttribute(NSParagraphStyleAttributeName, value: paragraphStyle, range: NSMakeRange(0, attributedString.length))
37-
attributedString.addAttribute(NSFontAttributeName, value: font!, range: NSMakeRange(0, attributedString.length))
36+
attributedString.addAttribute(NSAttributedStringKey.paragraphStyle, value: paragraphStyle, range: NSMakeRange(0, attributedString.length))
37+
attributedString.addAttribute(NSAttributedStringKey.font, value: font!, range: NSMakeRange(0, attributedString.length))
3838

3939
self.attributedText = attributedString
4040
}

Spring/DesignableTabBarController.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,20 @@ import UIKit
2727
@IBInspectable var normalTint: UIColor = UIColor.clear {
2828
didSet {
2929
UITabBar.appearance().tintColor = normalTint
30-
UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: normalTint], for: UIControlState())
30+
UITabBarItem.appearance().setTitleTextAttributes([NSAttributedStringKey.foregroundColor.rawValue: normalTint], for: UIControlState())
3131
}
3232
}
3333

3434
@IBInspectable var selectedTint: UIColor = UIColor.clear {
3535
didSet {
3636
UITabBar.appearance().tintColor = selectedTint
37-
UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: selectedTint], for:UIControlState.selected)
37+
UITabBarItem.appearance().setTitleTextAttributes([NSAttributedStringKey.foregroundColor.rawValue: selectedTint], for:UIControlState.selected)
3838
}
3939
}
4040

4141
@IBInspectable var fontName: String = "" {
4242
didSet {
43-
UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: normalTint, NSFontAttributeName: UIFont(name: fontName, size: 11)!], for: UIControlState())
43+
UITabBarItem.appearance().setTitleTextAttributes([NSAttributedStringKey.foregroundColor.rawValue: normalTint, NSAttributedStringKey.font.rawValue: UIFont(name: fontName, size: 11)!], for: UIControlState())
4444
}
4545
}
4646

Spring/DesignableTextField.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import UIKit
2626

2727
@IBInspectable public var placeholderColor: UIColor = UIColor.clear {
2828
didSet {
29-
attributedPlaceholder = NSAttributedString(string: placeholder!, attributes: [NSForegroundColorAttributeName: placeholderColor])
29+
attributedPlaceholder = NSAttributedString(string: placeholder!, attributes: [NSAttributedStringKey.foregroundColor: placeholderColor])
3030
layoutSubviews()
3131

3232
}
@@ -89,8 +89,8 @@ import UIKit
8989
paragraphStyle.lineSpacing = lineHeight
9090

9191
let attributedString = NSMutableAttributedString(string: text!)
92-
attributedString.addAttribute(NSParagraphStyleAttributeName, value: paragraphStyle, range: NSRange(location: 0, length: attributedString.length))
93-
attributedString.addAttribute(NSFontAttributeName, value: font!, range: NSRange(location: 0, length: attributedString.length))
92+
attributedString.addAttribute(NSAttributedStringKey.paragraphStyle, value: paragraphStyle, range: NSRange(location: 0, length: attributedString.length))
93+
attributedString.addAttribute(NSAttributedStringKey.font, value: font!, range: NSRange(location: 0, length: attributedString.length))
9494

9595
self.attributedText = attributedString
9696
}

Spring/DesignableTextView.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ import UIKit
5151
paragraphStyle.lineSpacing = lineHeight
5252

5353
let attributedString = NSMutableAttributedString(string: text!)
54-
attributedString.addAttribute(NSParagraphStyleAttributeName, value: paragraphStyle, range: NSRange(location: 0, length: attributedString.length))
55-
attributedString.addAttribute(NSFontAttributeName, value: font!, range: NSRange(location: 0, length: attributedString.length))
54+
attributedString.addAttribute(NSAttributedStringKey.paragraphStyle, value: paragraphStyle, range: NSRange(location: 0, length: attributedString.length))
55+
attributedString.addAttribute(NSAttributedStringKey.font, value: font!, range: NSRange(location: 0, length: attributedString.length))
5656

5757
self.attributedText = attributedString
5858
}

Spring/KeyboardLayoutConstraint.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class KeyboardLayoutConstraint: NSLayoutConstraint {
4242

4343
// MARK: Notification
4444

45-
func keyboardWillShowNotification(_ notification: Notification) {
45+
@objc func keyboardWillShowNotification(_ notification: Notification) {
4646
if let userInfo = notification.userInfo {
4747
if let frameValue = userInfo[UIKeyboardFrameEndUserInfoKey] as? NSValue {
4848
let frame = frameValue.cgRectValue
@@ -73,7 +73,7 @@ public class KeyboardLayoutConstraint: NSLayoutConstraint {
7373

7474
}
7575

76-
func keyboardWillHideNotification(_ notification: NSNotification) {
76+
@objc func keyboardWillHideNotification(_ notification: NSNotification) {
7777
keyboardVisibleHeight = 0
7878
self.updateConstant()
7979

Spring/Misc.swift

+3-2
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ public extension String {
3131
}
3232

3333
public func htmlToAttributedString(text: String) -> NSAttributedString! {
34-
let htmlData = text.data(using: String.Encoding.utf8, allowLossyConversion: false)
34+
guard let htmlData = text.data(using: String.Encoding.utf8, allowLossyConversion: false) else {
35+
return NSAttributedString() }
3536
let htmlString: NSAttributedString?
3637
do {
37-
htmlString = try NSAttributedString(data: htmlData!, options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], documentAttributes: nil)
38+
htmlString = try NSAttributedString(data: htmlData, options: [NSAttributedString.DocumentReadingOptionKey.documentType:NSAttributedString.DocumentType.html], documentAttributes: nil)
3839
} catch _ {
3940
htmlString = nil
4041
}

Spring/Spring.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public class Spring : NSObject {
6868
NotificationCenter.default.addObserver(self, selector: #selector(Spring.didBecomeActiveNotification(_:)), name: NSNotification.Name.UIApplicationDidBecomeActive, object: nil)
6969
}
7070

71-
func didBecomeActiveNotification(_ notification: NSNotification) {
71+
@objc func didBecomeActiveNotification(_ notification: NSNotification) {
7272
if shouldAnimateAfterActive {
7373
alpha = 0
7474
animate()

SpringApp.xcodeproj/project.pbxproj

+35-13
Original file line numberDiff line numberDiff line change
@@ -408,25 +408,25 @@
408408
isa = PBXProject;
409409
attributes = {
410410
LastSwiftUpdateCheck = 0700;
411-
LastUpgradeCheck = 0830;
411+
LastUpgradeCheck = 0900;
412412
ORGANIZATIONNAME = "Meng To";
413413
TargetAttributes = {
414414
1A4FDA321A6E44780099D309 = {
415415
CreatedOnToolsVersion = 6.1.1;
416-
LastSwiftMigration = 0800;
416+
LastSwiftMigration = 0900;
417417
};
418418
1A4FDA3C1A6E44780099D309 = {
419419
CreatedOnToolsVersion = 6.1.1;
420-
LastSwiftMigration = 0800;
420+
LastSwiftMigration = 0900;
421421
TestTargetID = 9641173A1A5BE90A000E3A5A;
422422
};
423423
9641173A1A5BE90A000E3A5A = {
424424
CreatedOnToolsVersion = 6.2;
425-
LastSwiftMigration = 0800;
425+
LastSwiftMigration = 0900;
426426
};
427427
9641174F1A5BE90A000E3A5A = {
428428
CreatedOnToolsVersion = 6.2;
429-
LastSwiftMigration = 0800;
429+
LastSwiftMigration = 0900;
430430
TestTargetID = 9641173A1A5BE90A000E3A5A;
431431
};
432432
};
@@ -615,7 +615,8 @@
615615
PRODUCT_BUNDLE_IDENTIFIER = "designcode.$(PRODUCT_NAME:rfc1034identifier)";
616616
PRODUCT_NAME = "$(TARGET_NAME)";
617617
SKIP_INSTALL = YES;
618-
SWIFT_VERSION = 3.0;
618+
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
619+
SWIFT_VERSION = 4.0;
619620
TARGETED_DEVICE_FAMILY = "1,2";
620621
VERSIONING_SYSTEM = "apple-generic";
621622
VERSION_INFO_PREFIX = "";
@@ -639,7 +640,8 @@
639640
PRODUCT_NAME = "$(TARGET_NAME)";
640641
SKIP_INSTALL = YES;
641642
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
642-
SWIFT_VERSION = 3.0;
643+
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
644+
SWIFT_VERSION = 4.0;
643645
TARGETED_DEVICE_FAMILY = "1,2";
644646
VERSIONING_SYSTEM = "apple-generic";
645647
VERSION_INFO_PREFIX = "";
@@ -658,7 +660,8 @@
658660
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
659661
PRODUCT_BUNDLE_IDENTIFIER = "com.jamztang.$(PRODUCT_NAME:rfc1034identifier)";
660662
PRODUCT_NAME = "$(TARGET_NAME)";
661-
SWIFT_VERSION = 3.0;
663+
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
664+
SWIFT_VERSION = 4.0;
662665
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SpringApp.app/SpringApp";
663666
};
664667
name = Debug;
@@ -672,7 +675,8 @@
672675
PRODUCT_BUNDLE_IDENTIFIER = "com.jamztang.$(PRODUCT_NAME:rfc1034identifier)";
673676
PRODUCT_NAME = "$(TARGET_NAME)";
674677
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
675-
SWIFT_VERSION = 3.0;
678+
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
679+
SWIFT_VERSION = 4.0;
676680
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SpringApp.app/SpringApp";
677681
};
678682
name = Release;
@@ -685,14 +689,20 @@
685689
CLANG_CXX_LIBRARY = "libc++";
686690
CLANG_ENABLE_MODULES = YES;
687691
CLANG_ENABLE_OBJC_ARC = YES;
692+
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
688693
CLANG_WARN_BOOL_CONVERSION = YES;
694+
CLANG_WARN_COMMA = YES;
689695
CLANG_WARN_CONSTANT_CONVERSION = YES;
690696
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
691697
CLANG_WARN_EMPTY_BODY = YES;
692698
CLANG_WARN_ENUM_CONVERSION = YES;
693699
CLANG_WARN_INFINITE_RECURSION = YES;
694700
CLANG_WARN_INT_CONVERSION = YES;
701+
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
702+
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
695703
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
704+
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
705+
CLANG_WARN_STRICT_PROTOTYPES = YES;
696706
CLANG_WARN_SUSPICIOUS_MOVE = YES;
697707
CLANG_WARN_UNREACHABLE_CODE = YES;
698708
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
@@ -720,6 +730,7 @@
720730
ONLY_ACTIVE_ARCH = YES;
721731
SDKROOT = iphoneos;
722732
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
733+
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
723734
};
724735
name = Debug;
725736
};
@@ -731,14 +742,20 @@
731742
CLANG_CXX_LIBRARY = "libc++";
732743
CLANG_ENABLE_MODULES = YES;
733744
CLANG_ENABLE_OBJC_ARC = YES;
745+
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
734746
CLANG_WARN_BOOL_CONVERSION = YES;
747+
CLANG_WARN_COMMA = YES;
735748
CLANG_WARN_CONSTANT_CONVERSION = YES;
736749
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
737750
CLANG_WARN_EMPTY_BODY = YES;
738751
CLANG_WARN_ENUM_CONVERSION = YES;
739752
CLANG_WARN_INFINITE_RECURSION = YES;
740753
CLANG_WARN_INT_CONVERSION = YES;
754+
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
755+
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
741756
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
757+
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
758+
CLANG_WARN_STRICT_PROTOTYPES = YES;
742759
CLANG_WARN_SUSPICIOUS_MOVE = YES;
743760
CLANG_WARN_UNREACHABLE_CODE = YES;
744761
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
@@ -757,6 +774,7 @@
757774
IPHONEOS_DEPLOYMENT_TARGET = 8.2;
758775
MTL_ENABLE_DEBUG_INFO = NO;
759776
SDKROOT = iphoneos;
777+
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
760778
VALIDATE_PRODUCT = YES;
761779
};
762780
name = Release;
@@ -770,7 +788,8 @@
770788
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
771789
PRODUCT_BUNDLE_IDENTIFIER = "designcode.$(PRODUCT_NAME:rfc1034identifier)";
772790
PRODUCT_NAME = "$(TARGET_NAME)";
773-
SWIFT_VERSION = 3.0;
791+
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
792+
SWIFT_VERSION = 4.0;
774793
TARGETED_DEVICE_FAMILY = "1,2";
775794
};
776795
name = Debug;
@@ -785,7 +804,8 @@
785804
PRODUCT_BUNDLE_IDENTIFIER = "designcode.$(PRODUCT_NAME:rfc1034identifier)";
786805
PRODUCT_NAME = "$(TARGET_NAME)";
787806
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
788-
SWIFT_VERSION = 3.0;
807+
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
808+
SWIFT_VERSION = 4.0;
789809
TARGETED_DEVICE_FAMILY = "1,2";
790810
};
791811
name = Release;
@@ -802,7 +822,8 @@
802822
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
803823
PRODUCT_BUNDLE_IDENTIFIER = "designcode.$(PRODUCT_NAME:rfc1034identifier)";
804824
PRODUCT_NAME = "$(TARGET_NAME)";
805-
SWIFT_VERSION = 3.0;
825+
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
826+
SWIFT_VERSION = 4.0;
806827
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SpringApp.app/SpringApp";
807828
};
808829
name = Debug;
@@ -816,7 +837,8 @@
816837
PRODUCT_BUNDLE_IDENTIFIER = "designcode.$(PRODUCT_NAME:rfc1034identifier)";
817838
PRODUCT_NAME = "$(TARGET_NAME)";
818839
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
819-
SWIFT_VERSION = 3.0;
840+
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
841+
SWIFT_VERSION = 4.0;
820842
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SpringApp.app/SpringApp";
821843
};
822844
name = Release;

SpringApp.xcodeproj/xcshareddata/xcschemes/Spring.xcscheme

+1-1
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"

SpringApp.xcodeproj/xcshareddata/xcschemes/SpringApp.xcscheme

+1-1
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"

SpringApp/CodeViewController.swift

+2
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,5 @@ class CodeViewController: UIViewController {
7575
UIApplication.shared.sendAction(#selector(SpringViewController.minimizeView(_:)), to: nil, from: self, for: nil)
7676
}
7777
}
78+
79+

SpringApp/SpringViewController.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,14 @@ class SpringViewController: UIViewController, UIPickerViewDelegate, UIPickerView
102102
ballView.curve = animationCurves[selectedEasing].rawValue
103103
}
104104

105-
func minimizeView(_ sender: AnyObject) {
105+
@objc func minimizeView(_ sender: AnyObject) {
106106
SpringAnimation.spring(duration: 0.7, animations: {
107107
self.view.transform = CGAffineTransform(scaleX: 0.935, y: 0.935)
108108
})
109109
UIApplication.shared.setStatusBarStyle(UIStatusBarStyle.lightContent, animated: true)
110110
}
111111

112-
func maximizeView(_ sender: AnyObject) {
112+
@objc func maximizeView(_ sender: AnyObject) {
113113
SpringAnimation.spring(duration: 0.7, animations: {
114114
self.view.transform = CGAffineTransform(scaleX: 1, y: 1)
115115
})

0 commit comments

Comments
 (0)