From b13c6c43b0bd313269e14fb4f4665c4d3115a863 Mon Sep 17 00:00:00 2001 From: Mike Peterson Date: Tue, 26 Sep 2017 07:56:11 -0500 Subject: [PATCH] Update for Swift 4.0 --- .../Drawing/ReferenceLineDrawingView.swift | 2 +- .../GraphView.xcodeproj/project.pbxproj | 21 ++++++++++++++++--- .../GraphView/UIColor+colorFromHex.swift | 2 +- .../GraphView/ViewController.swift | 4 ++-- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/Classes/Drawing/ReferenceLineDrawingView.swift b/Classes/Drawing/ReferenceLineDrawingView.swift index 965f399..240e38f 100644 --- a/Classes/Drawing/ReferenceLineDrawingView.swift +++ b/Classes/Drawing/ReferenceLineDrawingView.swift @@ -266,7 +266,7 @@ internal class ReferenceLineDrawingView : UIView { } private func boundingSize(forText text: String) -> CGSize { - return (text as NSString).size(attributes: [NSFontAttributeName:self.settings.referenceLineLabelFont]) + return (text as NSString).size(withAttributes: [NSAttributedStringKey.font:self.settings.referenceLineLabelFont]) } private func calculateYAxisValue(for point: CGPoint) -> Double { diff --git a/graphview_example_code/GraphView.xcodeproj/project.pbxproj b/graphview_example_code/GraphView.xcodeproj/project.pbxproj index 08a5095..28397c2 100644 --- a/graphview_example_code/GraphView.xcodeproj/project.pbxproj +++ b/graphview_example_code/GraphView.xcodeproj/project.pbxproj @@ -206,10 +206,11 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0720; - LastUpgradeCheck = 0800; + LastUpgradeCheck = 0900; TargetAttributes = { 2918399D1C72E6A400753A45 = { CreatedOnToolsVersion = 7.2.1; + DevelopmentTeam = JN7MAJGLHD; LastSwiftMigration = 0800; }; }; @@ -304,14 +305,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; @@ -350,14 +357,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; @@ -388,12 +401,13 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + DEVELOPMENT_TEAM = JN7MAJGLHD; INFOPLIST_FILE = GraphView/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.ios.GraphView; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE = ""; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -403,12 +417,13 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + DEVELOPMENT_TEAM = JN7MAJGLHD; INFOPLIST_FILE = GraphView/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.ios.GraphView; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE = ""; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; }; name = Release; }; diff --git a/graphview_example_code/GraphView/UIColor+colorFromHex.swift b/graphview_example_code/GraphView/UIColor+colorFromHex.swift index c69f221..5409eec 100644 --- a/graphview_example_code/GraphView/UIColor+colorFromHex.swift +++ b/graphview_example_code/GraphView/UIColor+colorFromHex.swift @@ -15,7 +15,7 @@ extension UIColor { // Remove the leading "#" if(hexString[hexString.startIndex] == "#") { - cleanedHexString = hexString.substring(from: hexString.characters.index(hexString.startIndex, offsetBy: 1)) + cleanedHexString = String(hexString[hexString.characters.index(hexString.startIndex, offsetBy: 1)...]) } // TODO: Other cleanup. Allow for a "short" hex string, i.e., "#fff" diff --git a/graphview_example_code/GraphView/ViewController.swift b/graphview_example_code/GraphView/ViewController.swift index f0b29f4..4a40206 100644 --- a/graphview_example_code/GraphView/ViewController.swift +++ b/graphview_example_code/GraphView/ViewController.swift @@ -509,7 +509,7 @@ class ViewController: UIViewController, ScrollableGraphViewDataSource { // Button tap events - func didTap(_ gesture: UITapGestureRecognizer) { + @objc func didTap(_ gesture: UITapGestureRecognizer) { currentGraphType.next() @@ -553,7 +553,7 @@ class ViewController: UIViewController, ScrollableGraphViewDataSource { setupConstraints() } - func reloadDidTap(_ gesture: UITapGestureRecognizer) { + @objc func reloadDidTap(_ gesture: UITapGestureRecognizer) { // TODO: Currently changing the number of data items is not supported. // It is only possible to change the the actual values of the data before reloading.