Skip to content

Commit 42cfde7

Browse files
authored
Merge pull request philackm#48 from dhf/master
Swift 3 migration
2 parents d3628c6 + 76830ed commit 42cfde7

File tree

9 files changed

+450
-447
lines changed

9 files changed

+450
-447
lines changed

Classes/ScrollableGraphView.swift

Lines changed: 294 additions & 302 deletions
Large diffs are not rendered by default.

graphview_example_code/GraphView.xcodeproj/project.pbxproj

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,11 @@
115115
isa = PBXProject;
116116
attributes = {
117117
LastSwiftUpdateCheck = 0720;
118-
LastUpgradeCheck = 0720;
118+
LastUpgradeCheck = 0800;
119119
TargetAttributes = {
120120
2918399D1C72E6A400753A45 = {
121121
CreatedOnToolsVersion = 7.2.1;
122+
LastSwiftMigration = 0800;
122123
};
123124
};
124125
};
@@ -200,8 +201,10 @@
200201
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
201202
CLANG_WARN_EMPTY_BODY = YES;
202203
CLANG_WARN_ENUM_CONVERSION = YES;
204+
CLANG_WARN_INFINITE_RECURSION = YES;
203205
CLANG_WARN_INT_CONVERSION = YES;
204206
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
207+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
205208
CLANG_WARN_UNREACHABLE_CODE = YES;
206209
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
207210
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@@ -244,8 +247,10 @@
244247
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
245248
CLANG_WARN_EMPTY_BODY = YES;
246249
CLANG_WARN_ENUM_CONVERSION = YES;
250+
CLANG_WARN_INFINITE_RECURSION = YES;
247251
CLANG_WARN_INT_CONVERSION = YES;
248252
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
253+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
249254
CLANG_WARN_UNREACHABLE_CODE = YES;
250255
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
251256
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@@ -264,6 +269,7 @@
264269
IPHONEOS_DEPLOYMENT_TARGET = 9.2;
265270
MTL_ENABLE_DEBUG_INFO = NO;
266271
SDKROOT = iphoneos;
272+
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
267273
VALIDATE_PRODUCT = YES;
268274
};
269275
name = Release;
@@ -279,6 +285,7 @@
279285
PRODUCT_BUNDLE_IDENTIFIER = com.ios.GraphView;
280286
PRODUCT_NAME = "$(TARGET_NAME)";
281287
PROVISIONING_PROFILE = "";
288+
SWIFT_VERSION = 3.0;
282289
};
283290
name = Debug;
284291
};
@@ -293,6 +300,7 @@
293300
PRODUCT_BUNDLE_IDENTIFIER = com.ios.GraphView;
294301
PRODUCT_NAME = "$(TARGET_NAME)";
295302
PROVISIONING_PROFILE = "";
303+
SWIFT_VERSION = 3.0;
296304
};
297305
name = Release;
298306
};

graphview_example_code/GraphView/AppDelegate.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,30 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1414
var window: UIWindow?
1515

1616

17-
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
17+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
1818
// Override point for customization after application launch.
1919
return true
2020
}
2121

22-
func applicationWillResignActive(application: UIApplication) {
22+
func applicationWillResignActive(_ application: UIApplication) {
2323
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
2424
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
2525
}
2626

27-
func applicationDidEnterBackground(application: UIApplication) {
27+
func applicationDidEnterBackground(_ application: UIApplication) {
2828
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
2929
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
3030
}
3131

32-
func applicationWillEnterForeground(application: UIApplication) {
32+
func applicationWillEnterForeground(_ application: UIApplication) {
3333
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
3434
}
3535

36-
func applicationDidBecomeActive(application: UIApplication) {
36+
func applicationDidBecomeActive(_ application: UIApplication) {
3737
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
3838
}
3939

40-
func applicationWillTerminate(application: UIApplication) {
40+
func applicationWillTerminate(_ application: UIApplication) {
4141
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
4242
}
4343

graphview_example_code/GraphView/UIColor+colorFromHex.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,35 @@ extension UIColor {
99
// Convert a hex string to a UIColor object.
1010
class func colorFromHex(hexString:String) -> UIColor {
1111

12-
func cleanHexString(hexString: String) -> String {
12+
func clean(hexString: String) -> String {
1313

1414
var cleanedHexString = String()
1515

1616
// Remove the leading "#"
1717
if(hexString[hexString.startIndex] == "#") {
18-
cleanedHexString = hexString.substringFromIndex(hexString.startIndex.advancedBy(1))
18+
cleanedHexString = hexString.substring(from: hexString.characters.index(hexString.startIndex, offsetBy: 1))
1919
}
2020

2121
// TODO: Other cleanup. Allow for a "short" hex string, i.e., "#fff"
2222

2323
return cleanedHexString
2424
}
2525

26-
let cleanedHexString = cleanHexString(hexString)
26+
let cleanedHexString = clean(hexString: hexString)
2727

2828
// If we can get a cached version of the colour, get out early.
29-
if let cachedColor = UIColor.getColorFromCache(cleanedHexString) {
29+
if let cachedColor = UIColor.getColorFromCache(hexString: cleanedHexString) {
3030
return cachedColor
3131
}
3232

3333
// Else create the color, store it in the cache and return.
34-
let scanner = NSScanner(string: cleanedHexString)
34+
let scanner = Scanner(string: cleanedHexString)
3535

3636
var value:UInt32 = 0
3737

3838
// We have the hex value, grab the red, green, blue and alpha values.
3939
// Have to pass value by reference, scanner modifies this directly as the result of scanning the hex string. The return value is the success or fail.
40-
if(scanner.scanHexInt(&value)){
40+
if(scanner.scanHexInt32(&value)){
4141

4242
// intValue = 01010101 11110111 11101010 // binary
4343
// intValue = 55 F7 EA // hexadecimal
@@ -70,23 +70,23 @@ extension UIColor {
7070
// red, green, blue and alpha are currently between 0 and 255
7171
// We want to normalise these values between 0 and 1 to use with UIColor.
7272
let colors:[UInt32] = [red, green, blue]
73-
let normalised = normaliseColors(colors)
73+
let normalised = normalise(colors: colors)
7474

7575
let newColor = UIColor(red: normalised[0], green: normalised[1], blue: normalised[2], alpha: 1)
76-
UIColor.storeColorInCache(cleanedHexString, color: newColor)
76+
UIColor.storeColorInCache(hexString: cleanedHexString, color: newColor)
7777

7878
return newColor
7979

8080
}
8181
// We couldn't get a value from a valid hex string.
8282
else {
8383
print("Error: Couldn't convert the hex string to a number, returning UIColor.whiteColor() instead.")
84-
return UIColor.whiteColor()
84+
return UIColor.white
8585
}
8686
}
8787

8888
// Takes an array of colours in the range of 0-255 and returns a value between 0 and 1.
89-
private class func normaliseColors(colors: [UInt32]) -> [CGFloat]{
89+
private class func normalise(colors: [UInt32]) -> [CGFloat]{
9090
var normalisedVersions = [CGFloat]()
9191

9292
for color in colors{

0 commit comments

Comments
 (0)