From c6e0552c7ccb2d1cb0ae8388e8641cac16debb5a Mon Sep 17 00:00:00 2001 From: hellyeah Date: Thu, 7 Apr 2016 17:12:55 -0400 Subject: [PATCH 1/2] update to latest swift syntax to fix errors --- ARPieChartDemo.xcodeproj/project.pbxproj | 2 ++ ARPieChartDemo/ARPieChart.swift | 34 ++++++++++++------------ ARPieChartDemo/ViewController.swift | 4 +-- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/ARPieChartDemo.xcodeproj/project.pbxproj b/ARPieChartDemo.xcodeproj/project.pbxproj index ccc0570..799bd1e 100644 --- a/ARPieChartDemo.xcodeproj/project.pbxproj +++ b/ARPieChartDemo.xcodeproj/project.pbxproj @@ -170,6 +170,8 @@ 8CF7458D1A82A540007B4C07 /* Project object */ = { isa = PBXProject; attributes = { + LastSwiftMigration = 0710; + LastSwiftUpdateCheck = 0710; LastUpgradeCheck = 0610; ORGANIZATIONNAME = "Yufei Tang"; TargetAttributes = { diff --git a/ARPieChartDemo/ARPieChart.swift b/ARPieChartDemo/ARPieChart.swift index f86103a..5c76b43 100644 --- a/ARPieChartDemo/ARPieChart.swift +++ b/ARPieChartDemo/ARPieChart.swift @@ -145,7 +145,7 @@ public class ARPieChart: UIView { if parentLayer.sublayers == nil { currentLayers = NSMutableArray() } else { - currentLayers = NSMutableArray(array: parentLayer.sublayers) + currentLayers = NSMutableArray(array: parentLayer.sublayers!) } var itemCount: Int = dataSource?.numberOfSlicesInPieChart(self) ?? 0 @@ -259,7 +259,7 @@ public class ARPieChart: UIView { } if layer.presentationLayer() != nil { - fromValue = layer.presentationLayer().valueForKey(key) + fromValue = layer.presentationLayer()!.valueForKey(key) } arcAnimation.fromValue = fromValue @@ -291,7 +291,7 @@ public class ARPieChart: UIView { var textLayer: CATextLayer! if layer.sublayers != nil { - textLayer = layer.sublayers.first as! CATextLayer + textLayer = layer.sublayers!.first as! CATextLayer } else { textLayer = CATextLayer() textLayer.contentsScale = UIScreen.mainScreen().scale @@ -308,7 +308,7 @@ public class ARPieChart: UIView { textLayer.string = dataSource?.pieChart(self, descriptionForSliceAtIndex: index) } - let size: CGSize = textLayer.string.sizeWithAttributes([NSFontAttributeName: labelFont]) + let size: CGSize = textLayer.string!.sizeWithAttributes([NSFontAttributeName: labelFont]) textLayer.frame = CGRectMake(0, 0, size.width, size.height) if (strokeEnd - strokeStart) * CGFloat(M_PI) * 2 * strokeRadius < max(size.width, size.height) { @@ -324,12 +324,12 @@ public class ARPieChart: UIView { let currentPieLayers = contentView.layer.sublayers - if currentPieLayers != nil && index < currentPieLayers.count { - let layerToSelect = currentPieLayers[index] as! CAShapeLayer - let currentPosition = layerToSelect.position - let midAngle = (layerToSelect.strokeEnd + layerToSelect.strokeStart) * CGFloat(M_PI) + startAngle + if currentPieLayers != nil && index < currentPieLayers!.count { + let layerToSelect = currentPieLayers?[index] as! CAShapeLayer? + let currentPosition = layerToSelect!.position + let midAngle = (layerToSelect!.strokeEnd + layerToSelect!.strokeStart) * CGFloat(M_PI) + startAngle let newPosition = CGPointMake(currentPosition.x + selectedPieOffset * cos(midAngle), currentPosition.y + selectedPieOffset * sin(midAngle)) - layerToSelect.position = newPosition + layerToSelect!.position = newPosition selectedLayerIndex = index } } @@ -338,8 +338,8 @@ public class ARPieChart: UIView { let currentPieLayers = contentView.layer.sublayers - if currentPieLayers != nil && index < currentPieLayers.count { - let layerToSelect = currentPieLayers[index] as! CAShapeLayer + if currentPieLayers != nil && index < currentPieLayers!.count { + let layerToSelect = currentPieLayers?[index] as! CAShapeLayer layerToSelect.position = CGPointMake(0, 0) layerToSelect.zPosition = 0 selectedLayerIndex = -1 @@ -356,9 +356,9 @@ public class ARPieChart: UIView { let point = touch.locationInView(contentView) - for var i = 0; i < currentPieLayers.count; i++ { + for var i = 0; i < currentPieLayers!.count; i++ { - let pieLayer = currentPieLayers[i] as! CAShapeLayer + let pieLayer = currentPieLayers?[i] as! CAShapeLayer let pieStartAngle = pieLayer.strokeStart * CGFloat(M_PI * 2) let pieEndAngle = pieLayer.strokeEnd * CGFloat(M_PI * 2) @@ -380,7 +380,7 @@ public class ARPieChart: UIView { return selectedIndex } - func handleLayerSelection(#fromIndex: Int, toIndex: Int) { + func handleLayerSelection(fromIndex fromIndex: Int, toIndex: Int) { if fromIndex == -1 && toIndex != -1 { selectLayerAtIndex(toIndex) delegate?.pieChart(self, itemSelectedAtIndex: toIndex) @@ -390,8 +390,8 @@ public class ARPieChart: UIView { } } - public override func touchesEnded(touches: Set, withEvent event: UIEvent) { - if let anyTouch: UITouch = touches.first as? UITouch { + public override func touchesEnded(touches: Set, withEvent event: UIEvent?) { + if let anyTouch: UITouch = touches.first! as UITouch { let selectedIndex = getSelectedLayerIndexOnTouch(anyTouch) handleLayerSelection(fromIndex: self.selectedLayerIndex, toIndex: selectedIndex) } @@ -405,7 +405,7 @@ public class ARPieChart: UIView { setDefaultValues() } - required public init(coder aDecoder: NSCoder) { + required public init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) setDefaultValues() } diff --git a/ARPieChartDemo/ViewController.swift b/ARPieChartDemo/ViewController.swift index ce46625..1837a88 100644 --- a/ARPieChartDemo/ViewController.swift +++ b/ARPieChartDemo/ViewController.swift @@ -61,7 +61,7 @@ class ViewController: UIViewController, ARPieChartDelegate, ARPieChartDataSource let indexToRemove: Int = randomInteger(0, upper: dataItems.count - 1) - println("Item removed at index \(indexToRemove)") + print("Item removed at index \(indexToRemove)") dataItems.removeObjectAtIndex(indexToRemove) pieChart.reloadData() @@ -70,7 +70,7 @@ class ViewController: UIViewController, ARPieChartDelegate, ARPieChartDataSource let indexToAdd: Int = randomInteger(0, upper: dataItems.count - 1) - println("Item added at index \(indexToAdd)") + print("Item added at index \(indexToAdd)") dataItems.insertObject(randomItem(), atIndex: indexToAdd) pieChart.reloadData() From b03ff127def23644fa05f3b87f140cea1f806ba7 Mon Sep 17 00:00:00 2001 From: hellyeah Date: Thu, 7 Apr 2016 17:28:26 -0400 Subject: [PATCH 2/2] make recommended changes and remove warnings by changing several variables to constants --- ARPieChartDemo.xcodeproj/project.pbxproj | 7 ++++++- ARPieChartDemo/ARPieChart.swift | 4 ++-- ARPieChartDemo/Info.plist | 2 +- ARPieChartDemoTests/Info.plist | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/ARPieChartDemo.xcodeproj/project.pbxproj b/ARPieChartDemo.xcodeproj/project.pbxproj index 799bd1e..7df0b49 100644 --- a/ARPieChartDemo.xcodeproj/project.pbxproj +++ b/ARPieChartDemo.xcodeproj/project.pbxproj @@ -172,7 +172,7 @@ attributes = { LastSwiftMigration = 0710; LastSwiftUpdateCheck = 0710; - LastUpgradeCheck = 0610; + LastUpgradeCheck = 0710; ORGANIZATIONNAME = "Yufei Tang"; TargetAttributes = { 8CF745941A82A540007B4C07 = { @@ -293,6 +293,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; GCC_OPTIMIZATION_LEVEL = 0; @@ -356,6 +357,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; INFOPLIST_FILE = ARPieChartDemo/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "com.yufei.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Debug; @@ -366,6 +368,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; INFOPLIST_FILE = ARPieChartDemo/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "com.yufei.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; @@ -384,6 +387,7 @@ ); INFOPLIST_FILE = ARPieChartDemoTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "com.yufei.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ARPieChartDemo.app/ARPieChartDemo"; }; @@ -399,6 +403,7 @@ ); INFOPLIST_FILE = ARPieChartDemoTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "com.yufei.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ARPieChartDemo.app/ARPieChartDemo"; }; diff --git a/ARPieChartDemo/ARPieChart.swift b/ARPieChartDemo/ARPieChart.swift index 5c76b43..8baad67 100644 --- a/ARPieChartDemo/ARPieChart.swift +++ b/ARPieChartDemo/ARPieChart.swift @@ -158,7 +158,7 @@ public class ARPieChart: UIView { var diff = itemCount - currentLayers.count - var layersToRemove: NSMutableArray = NSMutableArray() + let layersToRemove: NSMutableArray = NSMutableArray() /** * Begin CATransaction, disable user interaction @@ -226,7 +226,7 @@ public class ARPieChart: UIView { let currentValue: CGFloat = dataSource?.pieChart(self, valueForSliceAtIndex: index) ?? 0 - var layer = currentLayers[index] as! CAShapeLayer + let layer = currentLayers[index] as! CAShapeLayer toStrokeStart = currentTotal / total toStrokeEnd = (currentTotal + abs(currentValue)) / total diff --git a/ARPieChartDemo/Info.plist b/ARPieChartDemo/Info.plist index 83ff37d..6905cc6 100644 --- a/ARPieChartDemo/Info.plist +++ b/ARPieChartDemo/Info.plist @@ -7,7 +7,7 @@ CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier - com.yufei.$(PRODUCT_NAME:rfc1034identifier) + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName diff --git a/ARPieChartDemoTests/Info.plist b/ARPieChartDemoTests/Info.plist index 834e3fb..ba72822 100644 --- a/ARPieChartDemoTests/Info.plist +++ b/ARPieChartDemoTests/Info.plist @@ -7,7 +7,7 @@ CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier - com.yufei.$(PRODUCT_NAME:rfc1034identifier) + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName