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 Swift 3.0 and Xcode 8.2. #2

Open
wants to merge 1 commit 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
10 changes: 9 additions & 1 deletion Bezier.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,12 @@
5B61656B1BCE7FAD008EB160 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0710;
LastUpgradeCheck = 0820;
ORGANIZATIONNAME = "Y Media Labs";
TargetAttributes = {
5B6165721BCE7FAD008EB160 = {
CreatedOnToolsVersion = 7.1;
LastSwiftMigration = 0820;
};
};
};
Expand Down Expand Up @@ -182,8 +183,10 @@
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_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand Down Expand Up @@ -226,8 +229,10 @@
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_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand All @@ -246,6 +251,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 9.1;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
VALIDATE_PRODUCT = YES;
};
name = Release;
Expand All @@ -259,6 +265,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.ymedialabs.Bezier;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -271,6 +278,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.ymedialabs.Bezier;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand Down
12 changes: 6 additions & 6 deletions Bezier/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,30 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?


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

func applicationWillResignActive(application: UIApplication) {
func applicationWillResignActive(_ application: UIApplication) {
// 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.
// 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.
}

func applicationDidEnterBackground(application: UIApplication) {
func applicationDidEnterBackground(_ application: UIApplication) {
// 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.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(application: UIApplication) {
func applicationWillEnterForeground(_ application: UIApplication) {
// 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.
}

func applicationDidBecomeActive(application: UIApplication) {
func applicationDidBecomeActive(_ application: UIApplication) {
// 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.
}

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

Expand Down
42 changes: 21 additions & 21 deletions Bezier/BezierView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import UIKit
import Foundation

protocol BezierViewDataSource: class {
func bezierViewDataPoints(bezierView: BezierView) -> [CGPoint]
func bezierViewDataPoints(_ bezierView: BezierView) -> [CGPoint]
}

class BezierView: UIView {

private let kStrokeAnimationKey = "StrokeAnimationKey"
private let kFadeAnimationKey = "FadeAnimationKey"
fileprivate let kStrokeAnimationKey = "StrokeAnimationKey"
fileprivate let kFadeAnimationKey = "FadeAnimationKey"

//MARK: Public members
weak var dataSource: BezierViewDataSource?
Expand All @@ -30,11 +30,11 @@ class BezierView: UIView {

//MARK: Private members

private var dataPoints: [CGPoint]? {
fileprivate var dataPoints: [CGPoint]? {
return self.dataSource?.bezierViewDataPoints(self)
}

private let cubicCurveAlgorithm = CubicCurveAlgorithm()
fileprivate let cubicCurveAlgorithm = CubicCurveAlgorithm()

override func layoutSubviews() {
super.layoutSubviews()
Expand All @@ -50,7 +50,7 @@ class BezierView: UIView {
animateLayers()
}

private func drawPoints(){
fileprivate func drawPoints(){

guard let points = dataPoints else {
return
Expand All @@ -60,11 +60,11 @@ class BezierView: UIView {

let circleLayer = CAShapeLayer()
circleLayer.bounds = CGRect(x: 0, y: 0, width: 12, height: 12)
circleLayer.path = UIBezierPath(ovalInRect: circleLayer.bounds).CGPath
circleLayer.fillColor = UIColor(white: 248.0/255.0, alpha: 0.5).CGColor
circleLayer.path = UIBezierPath(ovalIn: circleLayer.bounds).cgPath
circleLayer.fillColor = UIColor(white: 248.0/255.0, alpha: 0.5).cgColor
circleLayer.position = point

circleLayer.shadowColor = UIColor.blackColor().CGColor
circleLayer.shadowColor = UIColor.black.cgColor
circleLayer.shadowOffset = CGSize(width: 0, height: 2)
circleLayer.shadowOpacity = 0.7
circleLayer.shadowRadius = 3.0
Expand All @@ -78,7 +78,7 @@ class BezierView: UIView {
}
}

private func drawSmoothLines() {
fileprivate func drawSmoothLines() {

guard let points = dataPoints else {
return
Expand All @@ -89,25 +89,25 @@ class BezierView: UIView {

let linePath = UIBezierPath()

for var i=0; i<points.count; i++ {
for i in 0 ..< points.count {

let point = points[i];

if i==0 {
linePath.moveToPoint(point)
linePath.move(to: point)
} else {
let segment = controlPoints[i-1]
linePath.addCurveToPoint(point, controlPoint1: segment.controlPoint1, controlPoint2: segment.controlPoint2)
linePath.addCurve(to: point, controlPoint1: segment.controlPoint1, controlPoint2: segment.controlPoint2)
}
}

lineLayer = CAShapeLayer()
lineLayer.path = linePath.CGPath
lineLayer.fillColor = UIColor.clearColor().CGColor
lineLayer.strokeColor = lineColor.CGColor
lineLayer.path = linePath.cgPath
lineLayer.fillColor = UIColor.clear.cgColor
lineLayer.strokeColor = lineColor.cgColor
lineLayer.lineWidth = 4.0

lineLayer.shadowColor = UIColor.blackColor().CGColor
lineLayer.shadowColor = UIColor.black.cgColor
lineLayer.shadowOffset = CGSize(width: 0, height: 8)
lineLayer.shadowOpacity = 0.5
lineLayer.shadowRadius = 6.0
Expand Down Expand Up @@ -139,8 +139,8 @@ extension BezierView {
fadeAnimation.duration = 0.2
fadeAnimation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
fadeAnimation.fillMode = kCAFillModeForwards
fadeAnimation.removedOnCompletion = false
point.addAnimation(fadeAnimation, forKey: kFadeAnimationKey)
fadeAnimation.isRemovedOnCompletion = false
point.add(fadeAnimation, forKey: kFadeAnimationKey)

delay += 0.15
}
Expand All @@ -154,8 +154,8 @@ extension BezierView {
growAnimation.duration = 1.5
growAnimation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseIn)
growAnimation.fillMode = kCAFillModeForwards
growAnimation.removedOnCompletion = false
lineLayer.addAnimation(growAnimation, forKey: kStrokeAnimationKey)
growAnimation.isRemovedOnCompletion = false
lineLayer.add(growAnimation, forKey: kStrokeAnimationKey)
}

}
Expand Down
22 changes: 11 additions & 11 deletions Bezier/CubicCurveAlgorithm.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ struct CubicCurveSegment

class CubicCurveAlgorithm
{
private var firstControlPoints: [CGPoint?] = []
private var secondControlPoints: [CGPoint?] = []
fileprivate var firstControlPoints: [CGPoint?] = []
fileprivate var secondControlPoints: [CGPoint?] = []

func controlPointsFromPoints(dataPoints: [CGPoint]) -> [CubicCurveSegment] {
func controlPointsFromPoints(_ dataPoints: [CGPoint]) -> [CubicCurveSegment] {

//Number of Segments
let count = dataPoints.count - 1
Expand All @@ -45,7 +45,7 @@ class CubicCurveAlgorithm

secondControlPoints.append(CGPoint(x: P2x, y: P2y))
} else {
firstControlPoints = Array(count: count, repeatedValue: nil)
firstControlPoints = Array(repeating: nil, count: count)

var rhsArray = [CGPoint]()

Expand All @@ -54,7 +54,7 @@ class CubicCurveAlgorithm
var b = [Double]()
var c = [Double]()

for var i=0; i<count; i++ {
for i in 0 ..< count {

var rhsValueX: CGFloat = 0
var rhsValueY: CGFloat = 0
Expand Down Expand Up @@ -93,7 +93,7 @@ class CubicCurveAlgorithm

//Solve Ax=B. Use Tridiagonal matrix algorithm a.k.a Thomas Algorithm

for var i=1; i<count; i++ {
for i in 1 ..< count {
let rhsValueX = rhsArray[i].x
let rhsValueY = rhsArray[i].y

Expand All @@ -119,8 +119,8 @@ class CubicCurveAlgorithm
let lastControlPointY = rhsArray[count-1].y.f/b[count-1]

firstControlPoints[count-1] = CGPoint(x: lastControlPointX, y: lastControlPointY)
for var i=count-2; i>=0; --i {

for i in stride(from: count - 2, through: 0, by: -1) {
if let nextControlPoint = firstControlPoints[i+1] {
let controlPointX = (rhsArray[i].x.f - c[i] * nextControlPoint.x.f)/b[i]
let controlPointY = (rhsArray[i].y.f - c[i] * nextControlPoint.y.f)/b[i]
Expand All @@ -132,7 +132,7 @@ class CubicCurveAlgorithm

//Compute second Control Points from first

for var i=0; i<count; i++ {
for i in 0 ..< count {

if i == count-1 {
let P3 = dataPoints[i+1]
Expand Down Expand Up @@ -163,9 +163,9 @@ class CubicCurveAlgorithm

var controlPoints = [CubicCurveSegment]()

for var i=0; i<count; i++ {
for i in 0 ..< count {
if let firstControlPoint = firstControlPoints[i],
secondControlPoint = secondControlPoints[i] {
let secondControlPoint = secondControlPoints[i] {
let segment = CubicCurveSegment(controlPoint1: firstControlPoint, controlPoint2: secondControlPoint)
controlPoints.append(segment)
}
Expand Down
6 changes: 3 additions & 3 deletions Bezier/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ViewController: UIViewController {
var xAxisPoints : [Double] {
var points = [Double]()
for i in 0..<dataPoints.count {
let val = (Double(i)/6.0) * CGRectGetWidth(self.firstBezierView.frame).f
let val = (Double(i)/6.0) * self.firstBezierView.frame.width.f
points.append(val)
}

Expand All @@ -28,7 +28,7 @@ class ViewController: UIViewController {
var yAxisPoints: [Double] {
var points = [Double]()
for i in dataPoints {
let val = (Double(i)/255) * CGRectGetHeight(self.firstBezierView.frame).f
let val = (Double(i)/255) * self.firstBezierView.frame.height.f
points.append(val)
}

Expand Down Expand Up @@ -60,7 +60,7 @@ class ViewController: UIViewController {

extension ViewController: BezierViewDataSource {

func bezierViewDataPoints(bezierView: BezierView) -> [CGPoint] {
func bezierViewDataPoints(_ bezierView: BezierView) -> [CGPoint] {

return graphPoints
}
Expand Down