Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to latest swift syntax to fix errors. #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion ARPieChartDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@
8CF7458D1A82A540007B4C07 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0610;
LastSwiftMigration = 0710;
LastSwiftUpdateCheck = 0710;
LastUpgradeCheck = 0710;
ORGANIZATIONNAME = "Yufei Tang";
TargetAttributes = {
8CF745941A82A540007B4C07 = {
Expand Down Expand Up @@ -291,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;
Expand Down Expand Up @@ -354,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;
Expand All @@ -364,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;
Expand All @@ -382,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";
};
Expand All @@ -397,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";
};
Expand Down
38 changes: 19 additions & 19 deletions ARPieChartDemo/ARPieChart.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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
}
}
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -390,8 +390,8 @@ public class ARPieChart: UIView {
}
}

public override func touchesEnded(touches: Set<NSObject>, withEvent event: UIEvent) {
if let anyTouch: UITouch = touches.first as? UITouch {
public override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
if let anyTouch: UITouch = touches.first! as UITouch {
let selectedIndex = getSelectedLayerIndexOnTouch(anyTouch)
handleLayerSelection(fromIndex: self.selectedLayerIndex, toIndex: selectedIndex)
}
Expand All @@ -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()
}
Expand Down
2 changes: 1 addition & 1 deletion ARPieChartDemo/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>com.yufei.$(PRODUCT_NAME:rfc1034identifier)</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand Down
4 changes: 2 additions & 2 deletions ARPieChartDemo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion ARPieChartDemoTests/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>com.yufei.$(PRODUCT_NAME:rfc1034identifier)</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand Down