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

Convert to Swift 4.2 #697

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
14 changes: 5 additions & 9 deletions C4.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -662,17 +662,17 @@
};
614F824219DB5ED3001DF1D4 = {
CreatedOnToolsVersion = 6.0;
LastSwiftMigration = 0900;
LastSwiftMigration = 1000;
};
614F824D19DB5ED4001DF1D4 = {
CreatedOnToolsVersion = 6.0;
LastSwiftMigration = 0900;
LastSwiftMigration = 1000;
TestTargetID = A96F50591B5385A5002B3A46;
};
A96F50591B5385A5002B3A46 = {
CreatedOnToolsVersion = 6.4;
DevelopmentTeam = 75C7KVJZ99;
LastSwiftMigration = 0900;
LastSwiftMigration = 1000;
};
};
};
Expand Down Expand Up @@ -1016,7 +1016,6 @@
SDKROOT = appletvos;
SKIP_INSTALL = YES;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 9.0;
};
Expand Down Expand Up @@ -1047,7 +1046,6 @@
SDKROOT = appletvos;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 9.0;
};
Expand All @@ -1071,7 +1069,6 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = appletvos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 9.0;
};
Expand All @@ -1096,7 +1093,6 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = appletvos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 9.0;
};
Expand Down Expand Up @@ -1155,7 +1151,7 @@
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand Down Expand Up @@ -1206,7 +1202,7 @@
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
Expand Down
4 changes: 3 additions & 1 deletion C4/UI/AudioPlayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ public class AudioPlayer: NSObject, AVAudioPlayerDelegate {
/// ````
public init?(_ name: String) {
do {
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
if #available(iOS 10.0, tvOS 10.0, *) {
try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default)
}
try AVAudioSession.sharedInstance().setActive(true)
} catch {
print("Couldn't set up AVAudioSession")
Expand Down
4 changes: 2 additions & 2 deletions C4/UI/Camera.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public class Camera: View {
previewLayer.backgroundColor = clear.cgColor
previewLayer.videoGravity = AVLayerVideoGravity.resizeAspectFill

orientationObserver = on(event: NSNotification.Name.UIDeviceOrientationDidChange) { [unowned self] in
orientationObserver = on(event: UIDevice.orientationDidChangeNotification) { [unowned self] in
self.updateOrientation()
}
}
Expand Down Expand Up @@ -191,7 +191,7 @@ public class Camera: View {
return image
}

var orientation: UIImageOrientation
var orientation: UIImage.Orientation
let shouldFlip = position == .front

switch videoOrientation {
Expand Down
6 changes: 4 additions & 2 deletions C4/UI/Movie.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ public class Movie: View {
/// - parameter filename: The name of the movie file included in your project.
public convenience init?(_ filename: String) {
do {
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
if #available(iOS 10.0, tvOS 10.0, *) {
try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default)
}
try AVAudioSession.sharedInstance().setActive(true)
} catch {
print("Couldn't set up AVAudioSession")
Expand Down Expand Up @@ -225,7 +227,7 @@ public class Movie: View {
print("The current movie's player is not properly initialized")
return
}
p.seek(to: CMTimeMake(0, 1))
p.seek(to: CMTimeMake(value: 0, timescale: 1))
p.pause()
}

Expand Down
30 changes: 15 additions & 15 deletions C4/UI/Shape.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ open class Shape: View {
return nil
}

let fillRule = shapeLayer.fillRule == kCAFillRuleNonZero ? CGPathFillRule.evenOdd : CGPathFillRule.winding
let fillRule = shapeLayer.fillRule == .nonZero ? CGPathFillRule.evenOdd : CGPathFillRule.winding

if path.contains(point, using: fillRule, transform: CGAffineTransform.identity) {
return self
Expand Down Expand Up @@ -216,9 +216,9 @@ open class Shape: View {
public var fillRule: FillRule {
get {
switch shapeLayer.fillRule {
case kCAFillRuleNonZero:
case .nonZero:
return .nonZero
case kCAFillRuleEvenOdd:
case .evenOdd:
return .evenOdd
default:
return .nonZero
Expand All @@ -227,9 +227,9 @@ open class Shape: View {
set(fillRule) {
switch fillRule {
case .nonZero:
shapeLayer.fillRule = kCAFillRuleNonZero
shapeLayer.fillRule = .nonZero
case .evenOdd:
shapeLayer.fillRule = kCAFillRuleEvenOdd
shapeLayer.fillRule = .evenOdd
}
}
}
Expand Down Expand Up @@ -275,9 +275,9 @@ open class Shape: View {
public var lineCap: LineCap {
get {
switch shapeLayer.lineCap {
case kCALineCapRound:
case .round:
return .round
case kCALineCapSquare:
case .square:
return .square
default:
return .butt
Expand All @@ -286,11 +286,11 @@ open class Shape: View {
set(lineCap) {
switch lineCap {
case .butt:
shapeLayer.lineCap = kCALineCapButt
shapeLayer.lineCap = .butt
case .round:
shapeLayer.lineCap = kCALineCapRound
shapeLayer.lineCap = .round
case .square:
shapeLayer.lineCap = kCALineCapSquare
shapeLayer.lineCap = .square
}
}
}
Expand All @@ -299,9 +299,9 @@ open class Shape: View {
public var lineJoin: LineJoin {
get {
switch shapeLayer.lineJoin {
case kCALineJoinRound:
case .round:
return .round
case kCALineJoinBevel:
case .bevel:
return .bevel
default:
return .miter
Expand All @@ -310,11 +310,11 @@ open class Shape: View {
set(lineJoin) {
switch lineJoin {
case .miter:
shapeLayer.lineJoin = kCALineJoinMiter
shapeLayer.lineJoin = .miter
case .round:
shapeLayer.lineJoin = kCALineJoinRound
shapeLayer.lineJoin = .round
case .bevel:
shapeLayer.lineJoin = kCALineJoinBevel
shapeLayer.lineJoin = .bevel
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion C4/UI/ShapeLayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ extension CABasicAnimation {
self.autoreverses = animation.autoreverses
self.repeatCount = Float(animation.repeatCount)
}
self.fillMode = kCAFillModeBoth
self.fillMode = .both
self.isRemovedOnCompletion = false
}
}
Expand Down
10 changes: 5 additions & 5 deletions C4/UI/StoredAnimation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,21 @@ public class StoredAnimation: Animation {
let disable = ShapeLayer.disableActions
ShapeLayer.disableActions = false
var timing: CAMediaTimingFunction
var options: UIViewAnimationOptions = [UIViewAnimationOptions.beginFromCurrentState]
var options: UIView.AnimationOptions = [.beginFromCurrentState]

switch curve {
case .linear:
options = [options, .curveLinear]
timing = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
timing = CAMediaTimingFunction(name: .linear)
case .easeOut:
options = [options, .curveEaseOut]
timing = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut)
timing = CAMediaTimingFunction(name: .easeOut)
case .easeIn:
options = [options, .curveEaseIn]
timing = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseIn)
timing = CAMediaTimingFunction(name: .easeIn)
case .easeInOut:
options = [options, .curveEaseIn, .curveEaseOut]
timing = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
timing = CAMediaTimingFunction(name: .easeInEaseOut)
}

autoreverses == true ? options.formUnion(.autoreverse) : options.subtract(.autoreverse)
Expand Down
2 changes: 1 addition & 1 deletion C4/UI/Timer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public final class Timer: NSObject {
}

let t = Foundation.Timer(timeInterval: TimeInterval(interval), target: self, selector: #selector(Timer.fire), userInfo: nil, repeats: true)
RunLoop.main.add(t, forMode: RunLoopMode.defaultRunLoopMode)
RunLoop.main.add(t, forMode: .default)
timer = t
}

Expand Down
14 changes: 7 additions & 7 deletions C4/UI/UIGestureRecognizer+Closure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ extension UIGestureRecognizer {
}
}

public typealias TapAction = (_ locations: [Point], _ center: Point, _ state: UIGestureRecognizerState) -> Void
public typealias TapAction = (_ locations: [Point], _ center: Point, _ state: UIGestureRecognizer.State) -> Void

extension UITapGestureRecognizer {
/// The closure to call when there is a gesture event.
Expand Down Expand Up @@ -107,7 +107,7 @@ extension UITapGestureRecognizer {
}
}

public typealias PanAction = (_ locations: [Point], _ center: Point, _ translation: Vector, _ velocity: Vector, _ state: UIGestureRecognizerState) -> Void
public typealias PanAction = (_ locations: [Point], _ center: Point, _ translation: Vector, _ velocity: Vector, _ state: UIGestureRecognizer.State) -> Void

extension UIPanGestureRecognizer {
/// The closure to call when there is a gesture event.
Expand Down Expand Up @@ -166,7 +166,7 @@ extension UIPanGestureRecognizer {
}
}

public typealias PinchAction = (_ locations: [Point], _ center: Point, _ scale: Double, _ velocity: Double, _ state: UIGestureRecognizerState) -> Void
public typealias PinchAction = (_ locations: [Point], _ center: Point, _ scale: Double, _ velocity: Double, _ state: UIGestureRecognizer.State) -> Void

extension UIPinchGestureRecognizer {
/// The closure to call when there is a gesture event.
Expand Down Expand Up @@ -207,7 +207,7 @@ extension UIPinchGestureRecognizer {
}
}

public typealias RotationAction = (_ rotation: Double, _ velocity: Double, _ state: UIGestureRecognizerState) -> Void
public typealias RotationAction = (_ rotation: Double, _ velocity: Double, _ state: UIGestureRecognizer.State) -> Void

extension UIRotationGestureRecognizer {
/// The closure to call when there is a gesture event.
Expand Down Expand Up @@ -244,7 +244,7 @@ extension UIRotationGestureRecognizer {
}
}

public typealias LongPressAction = (_ locations: [Point], _ center: Point, _ state: UIGestureRecognizerState) -> Void
public typealias LongPressAction = (_ locations: [Point], _ center: Point, _ state: UIGestureRecognizer.State) -> Void

extension UILongPressGestureRecognizer {
/// The closure to call when there is a gesture event.
Expand Down Expand Up @@ -285,7 +285,7 @@ extension UILongPressGestureRecognizer {
}
}

public typealias SwipeAction = (_ locations: [Point], _ center: Point, _ state: UIGestureRecognizerState, _ direction: UISwipeGestureRecognizerDirection) -> Void
public typealias SwipeAction = (_ locations: [Point], _ center: Point, _ state: UIGestureRecognizer.State, _ direction: UISwipeGestureRecognizer.Direction) -> Void

extension UISwipeGestureRecognizer {
/// The closure to call when there is a gesture event.
Expand Down Expand Up @@ -326,7 +326,7 @@ extension UISwipeGestureRecognizer {
}
}

public typealias ScreenEdgePanAction = (_ location: Point, _ state: UIGestureRecognizerState) -> Void
public typealias ScreenEdgePanAction = (_ location: Point, _ state: UIGestureRecognizer.State) -> Void

extension UIScreenEdgePanGestureRecognizer {
/// The closure to call when there is a gesture event.
Expand Down
8 changes: 4 additions & 4 deletions C4/UI/UIView+AddRemove.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ extension UIView {
/// - parameter subview: The subview to move to the back.
public func sendToBack<T>(_ subview: T?) {
if let v = subview as? UIView {
self.sendSubview(toBack: v)
self.sendSubviewToBack(v)
} else if let v = subview as? View {
self.sendSubview(toBack: v.view)
self.sendSubviewToBack(v.view)
} else {
fatalError("Can't operate on subview of class `\(type(of: subview))`")
}
Expand All @@ -85,9 +85,9 @@ extension UIView {
/// - parameter subview: The subview to move to the front.
public func bringToFront<T>(_ subview: T?) {
if let v = subview as? UIView {
self.bringSubview(toFront: v)
self.bringSubviewToFront(v)
} else if let v = subview as? View {
self.bringSubview(toFront: v.view)
self.bringSubviewToFront(v.view)
} else {
fatalError("Can't operate on subview of class `\(type(of: subview))`")
}
Expand Down
2 changes: 1 addition & 1 deletion C4/UI/View+Animation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public extension View {
/// - parameter options: Options for animating views using block objects, see: UIViewAnimationOptions.
/// - parameter animations: A block of code with specified animations to execute.
/// - parameter completion: A block of code to execute when the animation completes.
public class func animate(duration: Double, delay: Double, options: UIViewAnimationOptions, animations: @escaping () -> Void, completion: ((Bool) -> Void)?) {
public class func animate(duration: Double, delay: Double, options: UIView.AnimationOptions, animations: @escaping () -> Void, completion: ((Bool) -> Void)?) {
UIView.animate(withDuration: duration, delay: delay, options: options, animations: animations, completion: completion)
}
}
8 changes: 4 additions & 4 deletions C4/UI/View.swift
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,9 @@ open class View: NSObject {
/// - parameter subview: The subview to move to the back.
public func sendToBack<T>(_ subview: T?) {
if let v = subview as? UIView {
view.sendSubview(toBack: v)
view.sendSubviewToBack(v)
} else if let v = subview as? View {
view.sendSubview(toBack: v.view)
view.sendSubviewToBack(v.view)
} else {
fatalError("Can't operate on subview of class `\(type(of: subview))`")
}
Expand All @@ -387,9 +387,9 @@ open class View: NSObject {
/// - parameter subview: The subview to move to the front.
public func bringToFront<T>(_ subview: T?) {
if let v = subview as? UIView {
view.bringSubview(toFront: v)
view.bringSubviewToFront(v)
} else if let v = subview as? View {
view.bringSubview(toFront: v.view)
view.bringSubviewToFront(v.view)
} else {
fatalError("Can't operate on subview of class `\(type(of: subview))`")
}
Expand Down
12 changes: 6 additions & 6 deletions C4/UI/ViewAnimation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,19 @@ public class ViewAnimation: Animation {
public var timingFunction: CAMediaTimingFunction {
switch curve {
case .linear:
return CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
return CAMediaTimingFunction(name: .linear)
case .easeOut:
return CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut)
return CAMediaTimingFunction(name: .easeOut)
case .easeIn:
return CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseIn)
return CAMediaTimingFunction(name: .easeIn)
case .easeInOut:
return CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
return CAMediaTimingFunction(name: .easeInEaseOut)
}
}

///Options for animating views using block objects.
public var options: UIViewAnimationOptions {
var options: UIViewAnimationOptions = [UIViewAnimationOptions.beginFromCurrentState]
public var options: UIView.AnimationOptions {
var options: UIView.AnimationOptions = [.beginFromCurrentState]
switch curve {
case .linear:
options = [options, .curveLinear]
Expand Down