Skip to content

Commit

Permalink
Migrate to Swift 4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
philackm committed Oct 3, 2018
1 parent 7c82309 commit 9a5aafa
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 26 deletions.
9 changes: 7 additions & 2 deletions Classes/Drawing/GradientDrawingLayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ internal class GradientDrawingLayer : ScrollableGraphViewDrawingLayer {
let mask = CAShapeLayer()

mask.frame = CGRect(x: 0, y: 0, width: self.viewportWidth, height: self.viewportHeight)
mask.fillRule = kCAFillRuleEvenOdd
mask.fillRule = CAShapeLayerFillRule.evenOdd
mask.lineJoin = self.lineJoin

return mask
})()

init(frame: CGRect, startColor: UIColor, endColor: UIColor, gradientType: ScrollableGraphViewGradientType, lineJoin: String = kCALineJoinRound, lineDrawingLayer: LineDrawingLayer) {
init(frame: CGRect, startColor: UIColor, endColor: UIColor, gradientType: ScrollableGraphViewGradientType, lineJoin: String = convertFromCAShapeLayerLineJoin(CAShapeLayerLineJoin.round), lineDrawingLayer: LineDrawingLayer) {
self.startColor = startColor
self.endColor = endColor
self.gradientType = gradientType
Expand Down Expand Up @@ -68,3 +68,8 @@ internal class GradientDrawingLayer : ScrollableGraphViewDrawingLayer {
}
}
}

// Helper function inserted by Swift 4.2 migrator.
fileprivate func convertFromCAShapeLayerLineJoin(_ input: CAShapeLayerLineJoin) -> String {
return input.rawValue
}
14 changes: 12 additions & 2 deletions Classes/Drawing/LineDrawingLayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ internal class LineDrawingLayer : ScrollableGraphViewDrawingLayer {
self.lineWidth = lineWidth
self.strokeColor = lineColor.cgColor

self.lineJoin = lineJoin
self.lineCap = lineCap
self.lineJoin = convertToCAShapeLayerLineJoin(lineJoin)
self.lineCap = convertToCAShapeLayerLineCap(lineCap)

// Setup
self.fillColor = UIColor.clear.cgColor // This is handled by the fill drawing layer.
Expand Down Expand Up @@ -126,3 +126,13 @@ internal class LineDrawingLayer : ScrollableGraphViewDrawingLayer {
self.path = createLinePath().cgPath
}
}

// Helper function inserted by Swift 4.2 migrator.
fileprivate func convertToCAShapeLayerLineJoin(_ input: String) -> CAShapeLayerLineJoin {
return CAShapeLayerLineJoin(rawValue: input)
}

// Helper function inserted by Swift 4.2 migrator.
fileprivate func convertToCAShapeLayerLineCap(_ input: String) -> CAShapeLayerLineCap {
return CAShapeLayerLineCap(rawValue: input)
}
2 changes: 1 addition & 1 deletion Classes/Drawing/ReferenceLineDrawingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ internal class ReferenceLineDrawingView : UIView {

private func boundingSize(forText text: String) -> CGSize {
return (text as NSString).size(withAttributes:
[NSAttributedStringKey.font:self.settings.referenceLineLabelFont])
[NSAttributedString.Key.font:self.settings.referenceLineLabelFont])
}

private func calculateYAxisValue(for point: CGPoint) -> Double {
Expand Down
14 changes: 12 additions & 2 deletions Classes/Plots/LinePlot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ open class LinePlot : Plot {
open var lineStyle = ScrollableGraphViewLineStyle.straight

/// How each segment in the line should connect. Takes any of the Core Animation LineJoin values.
open var lineJoin: String = kCALineJoinRound
open var lineJoin: String = convertFromCAShapeLayerLineJoin(CAShapeLayerLineJoin.round)

/// The line caps. Takes any of the Core Animation LineCap values.
open var lineCap: String = kCALineCapRound
open var lineCap: String = convertFromCAShapeLayerLineCap(CAShapeLayerLineCap.round)
open var lineCurviness: CGFloat = 0.5


Expand Down Expand Up @@ -131,3 +131,13 @@ open class LinePlot : Plot {
case linear
case radial
}

// Helper function inserted by Swift 4.2 migrator.
fileprivate func convertFromCAShapeLayerLineJoin(_ input: CAShapeLayerLineJoin) -> String {
return input.rawValue
}

// Helper function inserted by Swift 4.2 migrator.
fileprivate func convertFromCAShapeLayerLineCap(_ input: CAShapeLayerLineCap) -> String {
return input.rawValue
}
2 changes: 1 addition & 1 deletion Classes/Plots/Plot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ open class Plot {

internal func setup() {
displayLink = CADisplayLink(target: self, selector: #selector(animationUpdate))
displayLink.add(to: RunLoop.main, forMode: RunLoopMode.commonModes)
displayLink.add(to: RunLoop.main, forMode: RunLoop.Mode.common)
displayLink.isPaused = true
}

Expand Down
10 changes: 5 additions & 5 deletions GraphView/GraphView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@
TargetAttributes = {
2918399D1C72E6A400753A45 = {
CreatedOnToolsVersion = 7.2.1;
LastSwiftMigration = 0800;
LastSwiftMigration = 1000;
};
};
};
Expand Down Expand Up @@ -512,7 +512,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.ios.GraphViewCode;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Debug;
};
Expand All @@ -529,7 +529,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.ios.GraphViewCode;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Release;
};
Expand All @@ -546,7 +546,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.ios.GraphViewIB;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Debug;
};
Expand All @@ -563,7 +563,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.ios.GraphViewIB;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Release;
};
Expand Down
2 changes: 1 addition & 1 deletion GraphView/GraphView/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
Expand Down
24 changes: 12 additions & 12 deletions GraphView/GraphViewCode/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ class ViewController: UIViewController {
self.graphView.translatesAutoresizingMaskIntoConstraints = false
graphConstraints.removeAll()

let topConstraint = NSLayoutConstraint(item: self.graphView, attribute: NSLayoutAttribute.top, relatedBy: NSLayoutRelation.equal, toItem: self.view, attribute: NSLayoutAttribute.top, multiplier: 1, constant: 0)
let rightConstraint = NSLayoutConstraint(item: self.graphView, attribute: NSLayoutAttribute.right, relatedBy: NSLayoutRelation.equal, toItem: self.view, attribute: NSLayoutAttribute.right, multiplier: 1, constant: 0)
let bottomConstraint = NSLayoutConstraint(item: self.graphView, attribute: NSLayoutAttribute.bottom, relatedBy: NSLayoutRelation.equal, toItem: self.view, attribute: NSLayoutAttribute.bottom, multiplier: 1, constant: 0)
let leftConstraint = NSLayoutConstraint(item: self.graphView, attribute: NSLayoutAttribute.left, relatedBy: NSLayoutRelation.equal, toItem: self.view, attribute: NSLayoutAttribute.left, multiplier: 1, constant: 0)
let topConstraint = NSLayoutConstraint(item: self.graphView, attribute: NSLayoutConstraint.Attribute.top, relatedBy: NSLayoutConstraint.Relation.equal, toItem: self.view, attribute: NSLayoutConstraint.Attribute.top, multiplier: 1, constant: 0)
let rightConstraint = NSLayoutConstraint(item: self.graphView, attribute: NSLayoutConstraint.Attribute.right, relatedBy: NSLayoutConstraint.Relation.equal, toItem: self.view, attribute: NSLayoutConstraint.Attribute.right, multiplier: 1, constant: 0)
let bottomConstraint = NSLayoutConstraint(item: self.graphView, attribute: NSLayoutConstraint.Attribute.bottom, relatedBy: NSLayoutConstraint.Relation.equal, toItem: self.view, attribute: NSLayoutConstraint.Attribute.bottom, multiplier: 1, constant: 0)
let leftConstraint = NSLayoutConstraint(item: self.graphView, attribute: NSLayoutConstraint.Attribute.left, relatedBy: NSLayoutConstraint.Relation.equal, toItem: self.view, attribute: NSLayoutConstraint.Attribute.left, multiplier: 1, constant: 0)

//let heightConstraint = NSLayoutConstraint(item: self.graphView, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.Height, multiplier: 1, constant: 0)

Expand All @@ -67,12 +67,12 @@ class ViewController: UIViewController {
label = createLabel(withText: text)
label.isUserInteractionEnabled = true

let rightConstraint = NSLayoutConstraint(item: label, attribute: NSLayoutAttribute.right, relatedBy: NSLayoutRelation.equal, toItem: self.view, attribute: NSLayoutAttribute.right, multiplier: 1, constant: -20)
let rightConstraint = NSLayoutConstraint(item: label, attribute: NSLayoutConstraint.Attribute.right, relatedBy: NSLayoutConstraint.Relation.equal, toItem: self.view, attribute: NSLayoutConstraint.Attribute.right, multiplier: 1, constant: -20)

let topConstraint = NSLayoutConstraint(item: label, attribute: NSLayoutAttribute.top, relatedBy: NSLayoutRelation.equal, toItem: self.view, attribute: NSLayoutAttribute.top, multiplier: 1, constant: 20)
let topConstraint = NSLayoutConstraint(item: label, attribute: NSLayoutConstraint.Attribute.top, relatedBy: NSLayoutConstraint.Relation.equal, toItem: self.view, attribute: NSLayoutConstraint.Attribute.top, multiplier: 1, constant: 20)

let heightConstraint = NSLayoutConstraint(item: label, attribute: NSLayoutAttribute.height, relatedBy: NSLayoutRelation.equal, toItem: nil, attribute: NSLayoutAttribute.notAnAttribute, multiplier: 1, constant: 40)
let widthConstraint = NSLayoutConstraint(item: label, attribute: NSLayoutAttribute.width, relatedBy: NSLayoutRelation.equal, toItem: nil, attribute: NSLayoutAttribute.notAnAttribute, multiplier: 1, constant: label.frame.width * 1.5)
let heightConstraint = NSLayoutConstraint(item: label, attribute: NSLayoutConstraint.Attribute.height, relatedBy: NSLayoutConstraint.Relation.equal, toItem: nil, attribute: NSLayoutConstraint.Attribute.notAnAttribute, multiplier: 1, constant: 40)
let widthConstraint = NSLayoutConstraint(item: label, attribute: NSLayoutConstraint.Attribute.width, relatedBy: NSLayoutConstraint.Relation.equal, toItem: nil, attribute: NSLayoutConstraint.Attribute.notAnAttribute, multiplier: 1, constant: label.frame.width * 1.5)

let tapGestureRecogniser = UITapGestureRecognizer(target: self, action: #selector(didTap))
label.addGestureRecognizer(tapGestureRecogniser)
Expand All @@ -87,12 +87,12 @@ class ViewController: UIViewController {
reloadLabel = createLabel(withText: text)
reloadLabel.isUserInteractionEnabled = true

let leftConstraint = NSLayoutConstraint(item: reloadLabel, attribute: NSLayoutAttribute.left, relatedBy: NSLayoutRelation.equal, toItem: self.view, attribute: NSLayoutAttribute.left, multiplier: 1, constant: 20)
let leftConstraint = NSLayoutConstraint(item: reloadLabel, attribute: NSLayoutConstraint.Attribute.left, relatedBy: NSLayoutConstraint.Relation.equal, toItem: self.view, attribute: NSLayoutConstraint.Attribute.left, multiplier: 1, constant: 20)

let topConstraint = NSLayoutConstraint(item: reloadLabel, attribute: NSLayoutAttribute.top, relatedBy: NSLayoutRelation.equal, toItem: self.view, attribute: NSLayoutAttribute.top, multiplier: 1, constant: 20)
let topConstraint = NSLayoutConstraint(item: reloadLabel, attribute: NSLayoutConstraint.Attribute.top, relatedBy: NSLayoutConstraint.Relation.equal, toItem: self.view, attribute: NSLayoutConstraint.Attribute.top, multiplier: 1, constant: 20)

let heightConstraint = NSLayoutConstraint(item: reloadLabel, attribute: NSLayoutAttribute.height, relatedBy: NSLayoutRelation.equal, toItem: nil, attribute: NSLayoutAttribute.notAnAttribute, multiplier: 1, constant: 40)
let widthConstraint = NSLayoutConstraint(item: reloadLabel, attribute: NSLayoutAttribute.width, relatedBy: NSLayoutRelation.equal, toItem: nil, attribute: NSLayoutAttribute.notAnAttribute, multiplier: 1, constant: reloadLabel.frame.width * 1.5)
let heightConstraint = NSLayoutConstraint(item: reloadLabel, attribute: NSLayoutConstraint.Attribute.height, relatedBy: NSLayoutConstraint.Relation.equal, toItem: nil, attribute: NSLayoutConstraint.Attribute.notAnAttribute, multiplier: 1, constant: 40)
let widthConstraint = NSLayoutConstraint(item: reloadLabel, attribute: NSLayoutConstraint.Attribute.width, relatedBy: NSLayoutConstraint.Relation.equal, toItem: nil, attribute: NSLayoutConstraint.Attribute.notAnAttribute, multiplier: 1, constant: reloadLabel.frame.width * 1.5)

let tapGestureRecogniser = UITapGestureRecognizer(target: self, action: #selector(reloadDidTap))
reloadLabel.addGestureRecognizer(tapGestureRecogniser)
Expand Down

0 comments on commit 9a5aafa

Please sign in to comment.