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 project to use Swift5 #699

Closed
wants to merge 7 commits into from
Closed
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
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: objective-c
osx_image: xcode9
osx_image: xcode11.3

script:
- xcodebuild clean build test -project C4.xcodeproj -scheme C4-iOS -destination 'platform=iOS Simulator,name=iPhone 6s,OS=9.3'
- xcodebuild clean build test -project C4.xcodeproj -scheme C4-iOS -destination 'platform=iOS Simulator,name=iPhone 6s,OS=10.3.1'
- xcodebuild clean build test -project C4.xcodeproj -scheme C4-tvOS -destination 'platform=tvOS Simulator,name=Apple TV 4K'
17 changes: 11 additions & 6 deletions C4.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
Base,
);
Expand Down Expand Up @@ -1016,7 +1017,7 @@
SDKROOT = appletvos;
SKIP_INSTALL = YES;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 9.0;
};
Expand Down Expand Up @@ -1047,7 +1048,7 @@
SDKROOT = appletvos;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 9.0;
};
Expand All @@ -1071,7 +1072,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = appletvos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 9.0;
};
Expand All @@ -1096,7 +1097,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = appletvos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 9.0;
};
Expand Down Expand Up @@ -1155,7 +1156,7 @@
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand Down Expand Up @@ -1206,7 +1207,7 @@
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
Expand All @@ -1229,6 +1230,7 @@
PRODUCT_NAME = C4;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -1247,6 +1249,7 @@
PRODUCT_NAME = C4;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand Down Expand Up @@ -1293,6 +1296,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.c4ios.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -1308,6 +1312,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.c4ios.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand Down
4 changes: 2 additions & 2 deletions C4/Core/Color.swift
Original file line number Diff line number Diff line change
Expand Up @@ -337,15 +337,15 @@ public class Color {
public extension UIColor {
/// Initializes a UIColor object from a Color object.
/// - parameter color: The C4 color object.
public convenience init?(_ color: Color) {
convenience init?(_ color: Color) {
self.init(cgColor: color.cgColor)
}
}

public extension CIColor {
/// Initializes a CIColor object from a Color object.
/// - parameter color: The C4 color object.
public convenience init(_ color: Color) {
convenience init(_ color: Color) {
self.init(cgColor: color.cgColor)
}
}
2 changes: 1 addition & 1 deletion C4/Core/Point.swift
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public func lerp(_ a: Point, _ b: Point, at: Double) -> Point {

public extension CGPoint {
///Initializes a CGPoint from a Point
public init(_ point: Point) {
init(_ point: Point) {
self.init(x: CGFloat(point.x), y: CGFloat(point.y))
}
}
2 changes: 1 addition & 1 deletion C4/Core/Rect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ public func inset(_ r: Rect, dx: Double, dy: Double) -> Rect {
// MARK: - Casting to CGRect
public extension CGRect {
/// Initializes a CGRect from a Rect
public init(_ rect: Rect) {
init(_ rect: Rect) {
self.init(origin: CGPoint(rect.origin), size: CGSize(rect.size))
}
}
2 changes: 1 addition & 1 deletion C4/Core/Size.swift
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public func <= (lhs: Size, rhs: Size) -> Bool {
// MARK: - Casting to CGSize
public extension CGSize {
/// Initializes a new CGSize from a Size
public init(_ size: Size) {
init(_ size: Size) {
self.init(width: CGFloat(size.width), height: CGFloat(size.height))
}
}
2 changes: 1 addition & 1 deletion C4/UI/AudioPlayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class AudioPlayer: NSObject, AVAudioPlayerDelegate {
/// ````
public init?(_ name: String) {
do {
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
try AVAudioSession.sharedInstance().setCategory(.playback)
try AVAudioSession.sharedInstance().setActive(true)
} catch {
print("Couldn't set up AVAudioSession")
Expand Down
6 changes: 4 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 All @@ -203,6 +203,8 @@ public class Camera: View {
orientation = shouldFlip ? .leftMirrored : .right
case .portraitUpsideDown:
orientation = shouldFlip ? .rightMirrored : .left
@unknown default:
orientation = shouldFlip ? .leftMirrored : .right
}
return UIImage(cgImage: cgimg, scale: image.scale, orientation: orientation)
}
Expand Down
2 changes: 1 addition & 1 deletion C4/UI/Image+ColorAt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public extension Image {
/// let color = img.color(at: Point())
/// ````
/// - parameter at: a Point.
public func color(at point: Point) -> Color {
func color(at point: Point) -> Color {

guard bounds.contains(point) else {
print("Point is outside the image bounds")
Expand Down
4 changes: 2 additions & 2 deletions C4/UI/Movie.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ 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)
try AVAudioSession.sharedInstance().setCategory(.playback)
try AVAudioSession.sharedInstance().setActive(true)
} catch {
print("Couldn't set up AVAudioSession")
Expand Down Expand Up @@ -225,7 +225,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: CGPathFillRule = shapeLayer.fillRule == CAShapeLayerFillRule.nonZero ? .evenOdd : .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
Loading