From 8478596bbc1410741f43c9c4a6d2668411220237 Mon Sep 17 00:00:00 2001 From: Josh Billions Date: Fri, 29 Nov 2019 16:21:08 -0600 Subject: [PATCH 01/11] Add Package Manifest --- C4.xcodeproj/project.pbxproj | 5 +++++ Package.swift | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 Package.swift diff --git a/C4.xcodeproj/project.pbxproj b/C4.xcodeproj/project.pbxproj index 3feed7ad..af473c1f 100644 --- a/C4.xcodeproj/project.pbxproj +++ b/C4.xcodeproj/project.pbxproj @@ -218,6 +218,8 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 138B93242391D042009219C5 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; + 138B93252391D052009219C5 /* Package.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Package.swift; sourceTree = ""; }; 1F40C6FA1C82ADF0004AE1E7 /* Camera.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Camera.swift; sourceTree = ""; }; 1F754DCA1C48EE600036D39F /* ImageLayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImageLayer.swift; sourceTree = ""; }; 1F75FDE81C5B1FE700EB62C2 /* C4Loop.aif */ = {isa = PBXFileReference; lastKnownFileType = file; path = C4Loop.aif; sourceTree = ""; }; @@ -358,6 +360,8 @@ 614F823919DB5ED3001DF1D4 = { isa = PBXGroup; children = ( + 138B93242391D042009219C5 /* README.md */, + 138B93252391D052009219C5 /* Package.swift */, A9D4F66E1B534F9F00F937AB /* C4 */, A9596D271A054A960023323D /* Tests */, A96F505B1B5385A5002B3A46 /* C4App */, @@ -681,6 +685,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, Base, ); diff --git a/Package.swift b/Package.swift new file mode 100644 index 00000000..05d726a0 --- /dev/null +++ b/Package.swift @@ -0,0 +1,23 @@ +// swift-tools-version:5.1 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "C4", + platforms: [.macOS(.v10_15), .iOS(.v9), .tvOS(.v9)], + products: [ + .library( + name: "C4", + targets: ["C4-iOS", "C4-tvOS"]), + ], + targets: [ + .target( + name: "C4", + path: "C4"), + .testTarget( + name: "C4Tests-iOS", + dependencies: ["C4"], + path: "TovalaKitTests"), + ] +) From 64af9f12d14502504f25f0e307cd15c291121f2c Mon Sep 17 00:00:00 2001 From: Josh Billions Date: Fri, 29 Nov 2019 16:22:49 -0600 Subject: [PATCH 02/11] Oops. Forgot Test Path. --- Package.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index 05d726a0..55d0faf0 100644 --- a/Package.swift +++ b/Package.swift @@ -18,6 +18,6 @@ let package = Package( .testTarget( name: "C4Tests-iOS", dependencies: ["C4"], - path: "TovalaKitTests"), + path: "Tests"), ] ) From 21f5c6b1f1b49376f7246e6e50a6b366fa29c7fc Mon Sep 17 00:00:00 2001 From: Josh Billions Date: Fri, 29 Nov 2019 16:27:21 -0600 Subject: [PATCH 03/11] Adding targets --- Package.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index 55d0faf0..628af462 100644 --- a/Package.swift +++ b/Package.swift @@ -13,8 +13,11 @@ let package = Package( ], targets: [ .target( - name: "C4", + name: "C4-iOS", path: "C4"), + .target( + name: "C4-tvOS", + path: "C4"), .testTarget( name: "C4Tests-iOS", dependencies: ["C4"], From 6e86e7753cda7dfb139d6867a031dc3a69f88ac6 Mon Sep 17 00:00:00 2001 From: Josh Billions Date: Fri, 29 Nov 2019 16:28:48 -0600 Subject: [PATCH 04/11] remove tvos --- Package.swift | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Package.swift b/Package.swift index 628af462..7698bd37 100644 --- a/Package.swift +++ b/Package.swift @@ -9,15 +9,12 @@ let package = Package( products: [ .library( name: "C4", - targets: ["C4-iOS", "C4-tvOS"]), + targets: ["C4-iOS"]), ], targets: [ .target( name: "C4-iOS", path: "C4"), - .target( - name: "C4-tvOS", - path: "C4"), .testTarget( name: "C4Tests-iOS", dependencies: ["C4"], From c603194a39d52f736d4abf8c7f8c3e9c5690c6f9 Mon Sep 17 00:00:00 2001 From: Josh Billions Date: Fri, 29 Nov 2019 16:29:49 -0600 Subject: [PATCH 05/11] Test Dependencies --- Package.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index 7698bd37..7c4eaa88 100644 --- a/Package.swift +++ b/Package.swift @@ -17,7 +17,7 @@ let package = Package( path: "C4"), .testTarget( name: "C4Tests-iOS", - dependencies: ["C4"], + dependencies: ["C4-iOS"], path: "Tests"), ] ) From b17f1fcf61e92cb8463dcefd7bc0e298d7e3dbb0 Mon Sep 17 00:00:00 2001 From: Josh Billions Date: Fri, 29 Nov 2019 16:31:12 -0600 Subject: [PATCH 06/11] Swift version --- Package.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index 7c4eaa88..8616281d 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.1 +// swift-tools-version:3.0 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription From fee42de533236f02a827dc8534f5e956da1079d9 Mon Sep 17 00:00:00 2001 From: Josh Billions Date: Fri, 29 Nov 2019 16:32:51 -0600 Subject: [PATCH 07/11] swift 4 --- Package.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index 8616281d..a7dad436 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:3.0 +// swift-tools-version:4.0 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription From 62801f6882fd670fb5ea36000cfa7ca18b832e2a Mon Sep 17 00:00:00 2001 From: Josh Billions Date: Fri, 29 Nov 2019 16:44:21 -0600 Subject: [PATCH 08/11] Swift 5 Changes --- C4.xcodeproj/project.pbxproj | 11 ++-- .../xcshareddata/xcschemes/C4-iOS.xcscheme | 24 ++++----- .../xcshareddata/xcschemes/C4-tvOS.xcscheme | 24 ++++----- C4/Core/Color.swift | 4 +- C4/Core/Point.swift | 2 +- C4/Core/Rect.swift | 2 +- C4/Core/Size.swift | 2 +- C4/UI/AudioPlayer.swift | 2 +- C4/UI/Camera.swift | 4 +- C4/UI/Image+ColorAt.swift | 2 +- C4/UI/Movie.swift | 4 +- C4/UI/Shape.swift | 50 +++++++++---------- C4/UI/ShapeLayer.swift | 2 +- C4/UI/StoredAnimation.swift | 10 ++-- C4/UI/Timer.swift | 2 +- C4/UI/UIGestureRecognizer+Closure.swift | 14 +++--- C4/UI/UIImage+Color.swift | 2 +- C4/UI/UIView+AddRemove.swift | 8 +-- C4/UI/UIViewController+C4View.swift | 2 +- C4/UI/View+Animation.swift | 6 +-- C4/UI/View+Border.swift | 2 +- C4/UI/View+Render.swift | 4 +- C4/UI/View+Shadow.swift | 2 +- C4/UI/View.swift | 8 +-- C4/UI/ViewAnimation.swift | 12 ++--- Package.swift | 2 +- 26 files changed, 100 insertions(+), 107 deletions(-) diff --git a/C4.xcodeproj/project.pbxproj b/C4.xcodeproj/project.pbxproj index af473c1f..165a12c0 100644 --- a/C4.xcodeproj/project.pbxproj +++ b/C4.xcodeproj/project.pbxproj @@ -653,7 +653,7 @@ attributes = { LastSwiftMigration = 0700; LastSwiftUpdateCheck = 0900; - LastUpgradeCheck = 1000; + LastUpgradeCheck = 1120; ORGANIZATIONNAME = C4; TargetAttributes = { 610A6A4D1F928E1B003B841A = { @@ -682,10 +682,9 @@ }; buildConfigurationList = 614F823D19DB5ED3001DF1D4 /* Build configuration list for PBXProject "C4" */; compatibilityVersion = "Xcode 8.0"; - developmentRegion = English; + developmentRegion = en; hasScannedForEncodings = 0; knownRegions = ( - English, en, Base, ); @@ -1111,6 +1110,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; @@ -1160,7 +1160,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 = ""; @@ -1171,6 +1171,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; @@ -1211,7 +1212,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"; diff --git a/C4.xcodeproj/xcshareddata/xcschemes/C4-iOS.xcscheme b/C4.xcodeproj/xcshareddata/xcschemes/C4-iOS.xcscheme index 83e9f074..f16856ca 100644 --- a/C4.xcodeproj/xcshareddata/xcschemes/C4-iOS.xcscheme +++ b/C4.xcodeproj/xcshareddata/xcschemes/C4-iOS.xcscheme @@ -1,6 +1,6 @@ + + + + @@ -39,17 +48,6 @@ - - - - - - - - + + + + @@ -39,17 +48,6 @@ - - - - - - - - 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)) } } diff --git a/C4/Core/Rect.swift b/C4/Core/Rect.swift index ba0308fd..adc9d4b9 100644 --- a/C4/Core/Rect.swift +++ b/C4/Core/Rect.swift @@ -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)) } } diff --git a/C4/Core/Size.swift b/C4/Core/Size.swift index 177fe286..185fe413 100644 --- a/C4/Core/Size.swift +++ b/C4/Core/Size.swift @@ -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)) } } diff --git a/C4/UI/AudioPlayer.swift b/C4/UI/AudioPlayer.swift index aa48373f..7ea94a40 100644 --- a/C4/UI/AudioPlayer.swift +++ b/C4/UI/AudioPlayer.swift @@ -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") diff --git a/C4/UI/Camera.swift b/C4/UI/Camera.swift index 3f62f6a1..ba12db46 100644 --- a/C4/UI/Camera.swift +++ b/C4/UI/Camera.swift @@ -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() } } @@ -191,7 +191,7 @@ public class Camera: View { return image } - var orientation: UIImageOrientation + var orientation: UIImage.Orientation let shouldFlip = position == .front switch videoOrientation { diff --git a/C4/UI/Image+ColorAt.swift b/C4/UI/Image+ColorAt.swift index b7d40e3f..0a8f03f5 100644 --- a/C4/UI/Image+ColorAt.swift +++ b/C4/UI/Image+ColorAt.swift @@ -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") diff --git a/C4/UI/Movie.swift b/C4/UI/Movie.swift index 83a9bb09..b11d845f 100644 --- a/C4/UI/Movie.swift +++ b/C4/UI/Movie.swift @@ -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") @@ -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() } diff --git a/C4/UI/Shape.swift b/C4/UI/Shape.swift index d30fc591..ff53510d 100644 --- a/C4/UI/Shape.swift +++ b/C4/UI/Shape.swift @@ -41,7 +41,7 @@ open class Shape: View { return nil } - let fillRule = shapeLayer.fillRule == kCAFillRuleNonZero ? CGPathFillRule.evenOdd : CGPathFillRule.winding + let fillRule = shapeLayer.fillRule == CAShapeLayerFillRule.nonZero ? CGPathFillRule.evenOdd : CGPathFillRule.winding if path.contains(point, using: fillRule, transform: CGAffineTransform.identity) { return self @@ -215,22 +215,22 @@ open class Shape: View { /// The fill rule used when filling the path. Defaults to `nonZero`. public var fillRule: FillRule { get { - switch shapeLayer.fillRule { - case kCAFillRuleNonZero: - return .nonZero - case kCAFillRuleEvenOdd: - return .evenOdd - default: - return .nonZero - } + switch shapeLayer.fillRule { + case .nonZero: + return .nonZero + case .evenOdd: + return .evenOdd + default: + return .nonZero + } } set(fillRule) { - switch fillRule { - case .nonZero: - shapeLayer.fillRule = kCAFillRuleNonZero - case .evenOdd: - shapeLayer.fillRule = kCAFillRuleEvenOdd - } + switch fillRule { + case .nonZero: + shapeLayer.fillRule = .nonZero + case .evenOdd: + shapeLayer.fillRule = .evenOdd + } } } @@ -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 @@ -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 } } } @@ -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 @@ -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 } } } diff --git a/C4/UI/ShapeLayer.swift b/C4/UI/ShapeLayer.swift index fada523a..4f5dd311 100644 --- a/C4/UI/ShapeLayer.swift +++ b/C4/UI/ShapeLayer.swift @@ -132,7 +132,7 @@ extension CABasicAnimation { self.autoreverses = animation.autoreverses self.repeatCount = Float(animation.repeatCount) } - self.fillMode = kCAFillModeBoth + self.fillMode = .both self.isRemovedOnCompletion = false } } diff --git a/C4/UI/StoredAnimation.swift b/C4/UI/StoredAnimation.swift index b05f9f7f..9e9cf77b 100644 --- a/C4/UI/StoredAnimation.swift +++ b/C4/UI/StoredAnimation.swift @@ -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: .easeOut) } autoreverses == true ? options.formUnion(.autoreverse) : options.subtract(.autoreverse) diff --git a/C4/UI/Timer.swift b/C4/UI/Timer.swift index d4147358..309e0c00 100644 --- a/C4/UI/Timer.swift +++ b/C4/UI/Timer.swift @@ -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 } diff --git a/C4/UI/UIGestureRecognizer+Closure.swift b/C4/UI/UIGestureRecognizer+Closure.swift index e62bea3f..8328135e 100644 --- a/C4/UI/UIGestureRecognizer+Closure.swift +++ b/C4/UI/UIGestureRecognizer+Closure.swift @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. diff --git a/C4/UI/UIImage+Color.swift b/C4/UI/UIImage+Color.swift index b391f71d..142d5a13 100644 --- a/C4/UI/UIImage+Color.swift +++ b/C4/UI/UIImage+Color.swift @@ -25,7 +25,7 @@ public extension UIImage { /// - parameter color: The color to use when creating the image. /// - parameter size: The size of image to create. /// - returns: A UIImage filled with the specified color and whose dimensions equal the give size - public class func createWithColor(_ color: UIColor, size: CGSize) -> UIImage { + class func createWithColor(_ color: UIColor, size: CGSize) -> UIImage { let rect = CGRect(x: 0, y: 0, width: size.width, height: size.height) UIGraphicsBeginImageContextWithOptions(size, false, 0) color.setFill() diff --git a/C4/UI/UIView+AddRemove.swift b/C4/UI/UIView+AddRemove.swift index 64d2e46c..94b43cdf 100644 --- a/C4/UI/UIView+AddRemove.swift +++ b/C4/UI/UIView+AddRemove.swift @@ -72,9 +72,9 @@ extension UIView { /// - parameter subview: The subview to move to the back. public func sendToBack(_ 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))`") } @@ -85,9 +85,9 @@ extension UIView { /// - parameter subview: The subview to move to the front. public func bringToFront(_ 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))`") } diff --git a/C4/UI/UIViewController+C4View.swift b/C4/UI/UIViewController+C4View.swift index d271f5e0..ac5d4d5c 100644 --- a/C4/UI/UIViewController+C4View.swift +++ b/C4/UI/UIViewController+C4View.swift @@ -38,7 +38,7 @@ private var canvasAssociationKey: UInt8 = 0 /// Where, `canvas` is essentially equal to `self.viewController.view`, keeping the interaction with a controller's main view consistent with using other View objects. public extension UIViewController { /// Returns a View object representation of the controller's `view` property. - public var canvas: View { + var canvas: View { if let canvas = objc_getAssociatedObject(self, &canvasAssociationKey) as? View { return canvas } diff --git a/C4/UI/View+Animation.swift b/C4/UI/View+Animation.swift index 7bd961d0..be822b22 100644 --- a/C4/UI/View+Animation.swift +++ b/C4/UI/View+Animation.swift @@ -40,7 +40,7 @@ public extension View { /// /// - parameter duration: The length of time in seconds for the animation to execute. /// - parameter animations: A block of code with specified animations to execute. - public class func animate(duration: Double, animations: @escaping () -> Void) { + class func animate(duration: Double, animations: @escaping () -> Void) { UIView.animate(withDuration: duration, animations: animations) } @@ -50,7 +50,7 @@ public extension View { /// - parameter delay: The length of time in seconds to wait before executing the specified block of code. /// - parameter completion: A block of code to execute when the animation completes. /// - parameter animations: A block of code with specified animations to execute. - public class func animate(duration: Double, delay: Double, animations: @escaping () -> Void, completion: ((Bool) -> Void)?) { + class func animate(duration: Double, delay: Double, animations: @escaping () -> Void, completion: ((Bool) -> Void)?) { UIView.animate(withDuration: duration, animations: animations, completion: completion) } @@ -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)?) { + 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) } } diff --git a/C4/UI/View+Border.swift b/C4/UI/View+Border.swift index cb006b82..85b85f14 100644 --- a/C4/UI/View+Border.swift +++ b/C4/UI/View+Border.swift @@ -57,7 +57,7 @@ public extension View { /// ```` /// /// Assigning a new value to this will change the `borderWidth`, `borderColor` and `cornderRadius` of the receiver's layer. - public var border: Border { + var border: Border { get { var border = Border() if let layer = layer { diff --git a/C4/UI/View+Render.swift b/C4/UI/View+Render.swift index c5e0b93c..2cef4c63 100644 --- a/C4/UI/View+Render.swift +++ b/C4/UI/View+Render.swift @@ -22,7 +22,7 @@ import UIKit public extension View { /// Creates a flattened image of the receiver and its subviews / layers. /// - returns: A new Image - @objc public func render() -> Image? { + @objc func render() -> Image? { guard let l = layer else { print("Could not retrieve layer for current object: \(self)") return nil @@ -40,7 +40,7 @@ public extension Shape { /// Creates a flattened image of the receiver and its subviews / layers. /// This override takes into consideration the lineWidth of the receiver. /// - returns: A new Image - public override func render() -> Image? { + override func render() -> Image? { var s = CGSize(size) var inset: CGFloat = 0 diff --git a/C4/UI/View+Shadow.swift b/C4/UI/View+Shadow.swift index 9317b229..9dc67dea 100644 --- a/C4/UI/View+Shadow.swift +++ b/C4/UI/View+Shadow.swift @@ -79,7 +79,7 @@ public extension View { /// v.shadow = s /// canvas.add(v) /// ```` - public var shadow: Shadow { + var shadow: Shadow { get { var shadow = Shadow() if let layer = layer { diff --git a/C4/UI/View.swift b/C4/UI/View.swift index 0faf73a1..26b95f96 100644 --- a/C4/UI/View.swift +++ b/C4/UI/View.swift @@ -375,9 +375,9 @@ open class View: NSObject { /// - parameter subview: The subview to move to the back. public func sendToBack(_ 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))`") } @@ -387,9 +387,9 @@ open class View: NSObject { /// - parameter subview: The subview to move to the front. public func bringToFront(_ 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))`") } diff --git a/C4/UI/ViewAnimation.swift b/C4/UI/ViewAnimation.swift index 97e9586b..99125a1d 100644 --- a/C4/UI/ViewAnimation.swift +++ b/C4/UI/ViewAnimation.swift @@ -95,19 +95,19 @@ public class ViewAnimation: Animation { public var timingFunction: CAMediaTimingFunction { switch curve { case .linear: - return CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear) + return CAMediaTimingFunction(name: CAMediaTimingFunctionName.linear) case .easeOut: - return CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut) + return CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeOut) case .easeIn: - return CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseIn) + return CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeIn) case .easeInOut: - return CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut) + return CAMediaTimingFunction(name: CAMediaTimingFunctionName.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] diff --git a/Package.swift b/Package.swift index a7dad436..7c4eaa88 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:4.0 +// swift-tools-version:5.1 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription From ab894f53fc6e38a888e1ccf311eef3a5ba8bbac9 Mon Sep 17 00:00:00 2001 From: Josh Billions Date: Fri, 29 Nov 2019 17:17:21 -0600 Subject: [PATCH 09/11] Get rid of tabs --- C4/Core/Color.swift | 4 +-- C4/UI/AudioPlayer.swift | 4 +-- C4/UI/Camera.swift | 72 ++++++++++++++++++++--------------------- 3 files changed, 40 insertions(+), 40 deletions(-) diff --git a/C4/Core/Color.swift b/C4/Core/Color.swift index 69a3498b..52c09d27 100644 --- a/C4/Core/Color.swift +++ b/C4/Core/Color.swift @@ -337,7 +337,7 @@ public class Color { public extension UIColor { /// Initializes a UIColor object from a Color object. /// - parameter color: The C4 color object. - convenience init?(_ color: Color) { + convenience init?(_ color: Color) { self.init(cgColor: color.cgColor) } } @@ -345,7 +345,7 @@ public extension UIColor { public extension CIColor { /// Initializes a CIColor object from a Color object. /// - parameter color: The C4 color object. - convenience init(_ color: Color) { + convenience init(_ color: Color) { self.init(cgColor: color.cgColor) } } diff --git a/C4/UI/AudioPlayer.swift b/C4/UI/AudioPlayer.swift index 7ea94a40..027a7958 100644 --- a/C4/UI/AudioPlayer.swift +++ b/C4/UI/AudioPlayer.swift @@ -48,9 +48,9 @@ public class AudioPlayer: NSObject, AVAudioPlayerDelegate { /// ```` public init?(_ name: String) { do { - try AVAudioSession.sharedInstance().setCategory(.playback) + try AVAudioSession.sharedInstance().setCategory(.playback) try AVAudioSession.sharedInstance().setActive(true) - } catch { + } catch { print("Couldn't set up AVAudioSession") } diff --git a/C4/UI/Camera.swift b/C4/UI/Camera.swift index ba12db46..17d75bd3 100644 --- a/C4/UI/Camera.swift +++ b/C4/UI/Camera.swift @@ -30,7 +30,7 @@ public class Camera: View { public var capturedImage: Image? public var quality = AVCaptureSession.Preset.photo public var position = CameraPosition.front - + var imageOutput: AVCaptureStillImageOutput? var captureDevice: AVCaptureDevice? var previewView: CameraView? @@ -39,44 +39,44 @@ public class Camera: View { var captureSession: AVCaptureSession? var didCaptureAction: (() -> Void)? var orientationObserver: Any? - + class CameraView: UIView { var previewLayer: PreviewLayer { return self.layer as! PreviewLayer // swiftlint:disable:this force_cast } - + override class var layerClass: AnyClass { return PreviewLayer.self } } - + var previewLayer: PreviewLayer { return self.cameraView.previewLayer } - + var cameraView: CameraView { return self.view as! CameraView // swiftlint:disable:this force_cast } - + public override init(frame: Rect) { super.init() view = CameraView() view.frame = CGRect(frame) - + previewLayer.backgroundColor = clear.cgColor previewLayer.videoGravity = AVLayerVideoGravity.resizeAspectFill - - orientationObserver = on(event: UIDevice.orientationDidChangeNotification) { [unowned self] in + + orientationObserver = on(event: UIDevice.orientationDidChangeNotification) { [unowned self] in self.updateOrientation() } } - + deinit { if let observer = orientationObserver { cancel(observer) } } - + public func startCapture(_ position: CameraPosition = .front) { self.position = position guard let cd = captureDevice(position) else { @@ -84,30 +84,30 @@ public class Camera: View { return } initializeInput(cd) - + guard input != nil else { print("Could not initialize input for \(cd)") return } initializeOutput(cd) captureDevice = cd - + initializeCaptureSession() - + captureSession?.startRunning() - + updateOrientation() } - + func captureDevice(_ position: CameraPosition) -> AVCaptureDevice? { return AVCaptureDevice.devices(for: AVMediaType.video).first(where: { $0.position.rawValue == position.rawValue }) } - + func updateOrientation() { guard let connection = previewLayer.connection, connection.isVideoOrientationSupported else { return } - + switch UIApplication.shared.statusBarOrientation { case .portraitUpsideDown: connection.videoOrientation = .portraitUpsideDown @@ -119,7 +119,7 @@ public class Camera: View { connection.videoOrientation = .portrait } } - + func initializeInput(_ device: AVCaptureDevice) { if input == nil { do { @@ -130,70 +130,70 @@ public class Camera: View { } } } - + func initializeOutput(_ device: AVCaptureDevice) { if stillImageOutput == nil { stillImageOutput = AVCaptureStillImageOutput() stillImageOutput?.outputSettings = [AVVideoCodecKey: AVVideoCodecJPEG] } } - + func initializeCaptureSession() { if captureSession == nil { captureSession = AVCaptureSession() previewLayer.session = captureSession } let session = captureSession! - + session.sessionPreset = quality - + for input in session.inputs { session.removeInput(input) } session.addInput(input!) - + for output in session.outputs { session.removeOutput(output) } session.addOutput(stillImageOutput!) } - + public func captureImage() { guard stillImageOutput?.isCapturingStillImage == false else { print("Still capturing, please wait until I'm done until you put me to work again") return } - + guard let connection = stillImageOutput?.connection(with: AVMediaType.video) else { return } - + updateOrientation() connection.videoOrientation = previewLayer.connection!.videoOrientation - + stillImageOutput?.captureStillImageAsynchronously(from: connection) { imageSampleBuffer, _ in guard imageSampleBuffer != nil else { print("Couldn't capture image from still image output") return } - + let data = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(imageSampleBuffer! as CMSampleBuffer) - + if let img = UIImage(data: data!) { self.capturedImage = Image(uiimage: self.orientRawImage(img)) self.didCaptureAction?() } } } - + func orientRawImage(_ image: UIImage) -> UIImage { guard let cgimg = image.cgImage, let videoOrientation = previewLayer.connection?.videoOrientation else { return image } - - var orientation: UIImage.Orientation + + var orientation: UIImage.Orientation let shouldFlip = position == .front - + switch videoOrientation { case .landscapeLeft: orientation = shouldFlip ? .upMirrored : .down @@ -206,12 +206,12 @@ public class Camera: View { } return UIImage(cgImage: cgimg, scale: image.scale, orientation: orientation) } - + public func didCaptureImage(_ action: (() -> Void)?) { didCaptureAction = action } } class PreviewLayer: AVCaptureVideoPreviewLayer { - + } From 88bcc76ff2b1164acb2b01a220e628b112519811 Mon Sep 17 00:00:00 2001 From: Josh Billions Date: Fri, 29 Nov 2019 22:23:12 -0600 Subject: [PATCH 10/11] More cleaning --- C4.xcodeproj/project.pbxproj | 18 +++++--- C4/Core/Point.swift | 2 +- C4/Core/Rect.swift | 2 +- C4/Core/Size.swift | 2 +- C4/UI/AudioPlayer.swift | 9 +++- C4/UI/Camera.swift | 68 ++++++++++++++--------------- C4/UI/Image+ColorAt.swift | 2 +- C4/UI/Movie.swift | 4 +- C4/UI/Shape.swift | 50 ++++++++++----------- C4/UI/ShapeLayer.swift | 2 +- C4/UI/StoredAnimation.swift | 10 ++--- C4/UI/Timer.swift | 2 +- C4/UI/UIImage+Color.swift | 2 +- C4/UI/UIView+AddRemove.swift | 8 ++-- C4/UI/UIViewController+C4View.swift | 2 +- C4/UI/View+Animation.swift | 6 +-- C4/UI/View+Border.swift | 2 +- C4/UI/View+Render.swift | 4 +- C4/UI/View+Shadow.swift | 2 +- C4/UI/View.swift | 8 ++-- C4/UI/ViewAnimation.swift | 12 ++--- 21 files changed, 113 insertions(+), 104 deletions(-) diff --git a/C4.xcodeproj/project.pbxproj b/C4.xcodeproj/project.pbxproj index 165a12c0..f06e3193 100644 --- a/C4.xcodeproj/project.pbxproj +++ b/C4.xcodeproj/project.pbxproj @@ -218,8 +218,7 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ - 138B93242391D042009219C5 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; - 138B93252391D052009219C5 /* Package.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Package.swift; sourceTree = ""; }; + 13470594239224A300B4BA4C /* Package.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Package.swift; sourceTree = ""; }; 1F40C6FA1C82ADF0004AE1E7 /* Camera.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Camera.swift; sourceTree = ""; }; 1F754DCA1C48EE600036D39F /* ImageLayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImageLayer.swift; sourceTree = ""; }; 1F75FDE81C5B1FE700EB62C2 /* C4Loop.aif */ = {isa = PBXFileReference; lastKnownFileType = file; path = C4Loop.aif; sourceTree = ""; }; @@ -360,8 +359,7 @@ 614F823919DB5ED3001DF1D4 = { isa = PBXGroup; children = ( - 138B93242391D042009219C5 /* README.md */, - 138B93252391D052009219C5 /* Package.swift */, + 13470594239224A300B4BA4C /* Package.swift */, A9D4F66E1B534F9F00F937AB /* C4 */, A9596D271A054A960023323D /* Tests */, A96F505B1B5385A5002B3A46 /* C4App */, @@ -666,17 +664,17 @@ }; 614F824219DB5ED3001DF1D4 = { CreatedOnToolsVersion = 6.0; - LastSwiftMigration = 0900; + LastSwiftMigration = 1120; }; 614F824D19DB5ED4001DF1D4 = { CreatedOnToolsVersion = 6.0; - LastSwiftMigration = 0900; + LastSwiftMigration = 1120; TestTargetID = A96F50591B5385A5002B3A46; }; A96F50591B5385A5002B3A46 = { CreatedOnToolsVersion = 6.4; DevelopmentTeam = 75C7KVJZ99; - LastSwiftMigration = 0900; + LastSwiftMigration = 1120; }; }; }; @@ -1235,6 +1233,7 @@ PRODUCT_NAME = C4; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -1253,6 +1252,7 @@ PRODUCT_NAME = C4; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = 5.0; }; name = Release; }; @@ -1268,6 +1268,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.c4ios.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/C4App.app/C4App"; }; name = Debug; @@ -1281,6 +1282,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.c4ios.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = 5.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/C4App.app/C4App"; }; name = Release; @@ -1299,6 +1301,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; }; @@ -1314,6 +1317,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.c4ios.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = 5.0; }; name = Release; }; diff --git a/C4/Core/Point.swift b/C4/Core/Point.swift index c9611953..17832b91 100644 --- a/C4/Core/Point.swift +++ b/C4/Core/Point.swift @@ -187,7 +187,7 @@ public func lerp(_ a: Point, _ b: Point, at: Double) -> Point { public extension CGPoint { ///Initializes a CGPoint from a Point - init(_ point: Point) { + init(_ point: Point) { self.init(x: CGFloat(point.x), y: CGFloat(point.y)) } } diff --git a/C4/Core/Rect.swift b/C4/Core/Rect.swift index adc9d4b9..0edf2170 100644 --- a/C4/Core/Rect.swift +++ b/C4/Core/Rect.swift @@ -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 - init(_ rect: Rect) { + init(_ rect: Rect) { self.init(origin: CGPoint(rect.origin), size: CGSize(rect.size)) } } diff --git a/C4/Core/Size.swift b/C4/Core/Size.swift index 185fe413..c5b5fb55 100644 --- a/C4/Core/Size.swift +++ b/C4/Core/Size.swift @@ -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 - init(_ size: Size) { + init(_ size: Size) { self.init(width: CGFloat(size.width), height: CGFloat(size.height)) } } diff --git a/C4/UI/AudioPlayer.swift b/C4/UI/AudioPlayer.swift index 027a7958..eeb64b81 100644 --- a/C4/UI/AudioPlayer.swift +++ b/C4/UI/AudioPlayer.swift @@ -48,9 +48,9 @@ public class AudioPlayer: NSObject, AVAudioPlayerDelegate { /// ```` public init?(_ name: String) { do { - try AVAudioSession.sharedInstance().setCategory(.playback) + try AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category(rawValue: convertFromAVAudioSessionCategory(AVAudioSession.Category.playback))) try AVAudioSession.sharedInstance().setActive(true) - } catch { + } catch { print("Couldn't set up AVAudioSession") } @@ -248,3 +248,8 @@ public class AudioPlayer: NSObject, AVAudioPlayerDelegate { return Double(player.peakPower(forChannel: channel)) } } + +// Helper function inserted by Swift 4.2 migrator. +private func convertFromAVAudioSessionCategory(_ input: AVAudioSession.Category) -> String { + return input.rawValue +} diff --git a/C4/UI/Camera.swift b/C4/UI/Camera.swift index 17d75bd3..c5a58603 100644 --- a/C4/UI/Camera.swift +++ b/C4/UI/Camera.swift @@ -30,7 +30,7 @@ public class Camera: View { public var capturedImage: Image? public var quality = AVCaptureSession.Preset.photo public var position = CameraPosition.front - + var imageOutput: AVCaptureStillImageOutput? var captureDevice: AVCaptureDevice? var previewView: CameraView? @@ -39,44 +39,44 @@ public class Camera: View { var captureSession: AVCaptureSession? var didCaptureAction: (() -> Void)? var orientationObserver: Any? - + class CameraView: UIView { var previewLayer: PreviewLayer { return self.layer as! PreviewLayer // swiftlint:disable:this force_cast } - + override class var layerClass: AnyClass { return PreviewLayer.self } } - + var previewLayer: PreviewLayer { return self.cameraView.previewLayer } - + var cameraView: CameraView { return self.view as! CameraView // swiftlint:disable:this force_cast } - + public override init(frame: Rect) { super.init() view = CameraView() view.frame = CGRect(frame) - + previewLayer.backgroundColor = clear.cgColor previewLayer.videoGravity = AVLayerVideoGravity.resizeAspectFill - + orientationObserver = on(event: UIDevice.orientationDidChangeNotification) { [unowned self] in self.updateOrientation() } } - + deinit { if let observer = orientationObserver { cancel(observer) } } - + public func startCapture(_ position: CameraPosition = .front) { self.position = position guard let cd = captureDevice(position) else { @@ -84,30 +84,30 @@ public class Camera: View { return } initializeInput(cd) - + guard input != nil else { print("Could not initialize input for \(cd)") return } initializeOutput(cd) captureDevice = cd - + initializeCaptureSession() - + captureSession?.startRunning() - + updateOrientation() } - + func captureDevice(_ position: CameraPosition) -> AVCaptureDevice? { return AVCaptureDevice.devices(for: AVMediaType.video).first(where: { $0.position.rawValue == position.rawValue }) } - + func updateOrientation() { guard let connection = previewLayer.connection, connection.isVideoOrientationSupported else { return } - + switch UIApplication.shared.statusBarOrientation { case .portraitUpsideDown: connection.videoOrientation = .portraitUpsideDown @@ -119,7 +119,7 @@ public class Camera: View { connection.videoOrientation = .portrait } } - + func initializeInput(_ device: AVCaptureDevice) { if input == nil { do { @@ -130,70 +130,70 @@ public class Camera: View { } } } - + func initializeOutput(_ device: AVCaptureDevice) { if stillImageOutput == nil { stillImageOutput = AVCaptureStillImageOutput() stillImageOutput?.outputSettings = [AVVideoCodecKey: AVVideoCodecJPEG] } } - + func initializeCaptureSession() { if captureSession == nil { captureSession = AVCaptureSession() previewLayer.session = captureSession } let session = captureSession! - + session.sessionPreset = quality - + for input in session.inputs { session.removeInput(input) } session.addInput(input!) - + for output in session.outputs { session.removeOutput(output) } session.addOutput(stillImageOutput!) } - + public func captureImage() { guard stillImageOutput?.isCapturingStillImage == false else { print("Still capturing, please wait until I'm done until you put me to work again") return } - + guard let connection = stillImageOutput?.connection(with: AVMediaType.video) else { return } - + updateOrientation() connection.videoOrientation = previewLayer.connection!.videoOrientation - + stillImageOutput?.captureStillImageAsynchronously(from: connection) { imageSampleBuffer, _ in guard imageSampleBuffer != nil else { print("Couldn't capture image from still image output") return } - + let data = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(imageSampleBuffer! as CMSampleBuffer) - + if let img = UIImage(data: data!) { self.capturedImage = Image(uiimage: self.orientRawImage(img)) self.didCaptureAction?() } } } - + func orientRawImage(_ image: UIImage) -> UIImage { guard let cgimg = image.cgImage, let videoOrientation = previewLayer.connection?.videoOrientation else { return image } - + var orientation: UIImage.Orientation let shouldFlip = position == .front - + switch videoOrientation { case .landscapeLeft: orientation = shouldFlip ? .upMirrored : .down @@ -206,12 +206,12 @@ public class Camera: View { } return UIImage(cgImage: cgimg, scale: image.scale, orientation: orientation) } - + public func didCaptureImage(_ action: (() -> Void)?) { didCaptureAction = action } } class PreviewLayer: AVCaptureVideoPreviewLayer { - + } diff --git a/C4/UI/Image+ColorAt.swift b/C4/UI/Image+ColorAt.swift index 0a8f03f5..339c01a5 100644 --- a/C4/UI/Image+ColorAt.swift +++ b/C4/UI/Image+ColorAt.swift @@ -50,7 +50,7 @@ public extension Image { /// let color = img.color(at: Point()) /// ```` /// - parameter at: a Point. - func color(at point: Point) -> Color { + func color(at point: Point) -> Color { guard bounds.contains(point) else { print("Point is outside the image bounds") diff --git a/C4/UI/Movie.swift b/C4/UI/Movie.swift index b11d845f..c9b308c9 100644 --- a/C4/UI/Movie.swift +++ b/C4/UI/Movie.swift @@ -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(.playback) + try AVAudioSession.sharedInstance().setCategory(.playback) try AVAudioSession.sharedInstance().setActive(true) } catch { print("Couldn't set up AVAudioSession") @@ -225,7 +225,7 @@ public class Movie: View { print("The current movie's player is not properly initialized") return } - p.seek(to: CMTimeMake(value: 0, timescale: 1)) + p.seek(to: CMTimeMake(value: 0, timescale: 1)) p.pause() } diff --git a/C4/UI/Shape.swift b/C4/UI/Shape.swift index ff53510d..e19d56d6 100644 --- a/C4/UI/Shape.swift +++ b/C4/UI/Shape.swift @@ -41,7 +41,7 @@ open class Shape: View { return nil } - let fillRule = shapeLayer.fillRule == CAShapeLayerFillRule.nonZero ? CGPathFillRule.evenOdd : CGPathFillRule.winding + let fillRule = shapeLayer.fillRule == CAShapeLayerFillRule.nonZero ? CGPathFillRule.evenOdd : CGPathFillRule.winding if path.contains(point, using: fillRule, transform: CGAffineTransform.identity) { return self @@ -215,22 +215,22 @@ open class Shape: View { /// The fill rule used when filling the path. Defaults to `nonZero`. public var fillRule: FillRule { get { - switch shapeLayer.fillRule { - case .nonZero: - return .nonZero - case .evenOdd: - return .evenOdd - default: - return .nonZero - } + switch shapeLayer.fillRule { + case .nonZero: + return .nonZero + case .evenOdd: + return .evenOdd + default: + return .nonZero + } } set(fillRule) { - switch fillRule { - case .nonZero: - shapeLayer.fillRule = .nonZero - case .evenOdd: - shapeLayer.fillRule = .evenOdd - } + switch fillRule { + case .nonZero: + shapeLayer.fillRule = .nonZero + case .evenOdd: + shapeLayer.fillRule = .evenOdd + } } } @@ -275,9 +275,9 @@ open class Shape: View { public var lineCap: LineCap { get { switch shapeLayer.lineCap { - case .round: + case .round: return .round - case .square: + case .square: return .square default: return .butt @@ -286,11 +286,11 @@ open class Shape: View { set(lineCap) { switch lineCap { case .butt: - shapeLayer.lineCap = .butt + shapeLayer.lineCap = .butt case .round: - shapeLayer.lineCap = .round + shapeLayer.lineCap = .round case .square: - shapeLayer.lineCap = .square + shapeLayer.lineCap = .square } } } @@ -299,9 +299,9 @@ open class Shape: View { public var lineJoin: LineJoin { get { switch shapeLayer.lineJoin { - case .round: + case .round: return .round - case .bevel: + case .bevel: return .bevel default: return .miter @@ -310,11 +310,11 @@ open class Shape: View { set(lineJoin) { switch lineJoin { case .miter: - shapeLayer.lineJoin = .miter + shapeLayer.lineJoin = .miter case .round: - shapeLayer.lineJoin = .round + shapeLayer.lineJoin = .round case .bevel: - shapeLayer.lineJoin = .bevel + shapeLayer.lineJoin = .bevel } } } diff --git a/C4/UI/ShapeLayer.swift b/C4/UI/ShapeLayer.swift index 4f5dd311..fdfe9755 100644 --- a/C4/UI/ShapeLayer.swift +++ b/C4/UI/ShapeLayer.swift @@ -132,7 +132,7 @@ extension CABasicAnimation { self.autoreverses = animation.autoreverses self.repeatCount = Float(animation.repeatCount) } - self.fillMode = .both + self.fillMode = .both self.isRemovedOnCompletion = false } } diff --git a/C4/UI/StoredAnimation.swift b/C4/UI/StoredAnimation.swift index 9e9cf77b..aecee79f 100644 --- a/C4/UI/StoredAnimation.swift +++ b/C4/UI/StoredAnimation.swift @@ -34,21 +34,21 @@ public class StoredAnimation: Animation { let disable = ShapeLayer.disableActions ShapeLayer.disableActions = false var timing: CAMediaTimingFunction - var options: UIView.AnimationOptions = [.beginFromCurrentState] + var options: UIView.AnimationOptions = [.beginFromCurrentState] switch curve { case .linear: options = [options, .curveLinear] - timing = CAMediaTimingFunction(name: .linear) + timing = CAMediaTimingFunction(name: .linear) case .easeOut: options = [options, .curveEaseOut] - timing = CAMediaTimingFunction(name: .easeOut) + timing = CAMediaTimingFunction(name: .easeOut) case .easeIn: options = [options, .curveEaseIn] - timing = CAMediaTimingFunction(name: .easeIn) + timing = CAMediaTimingFunction(name: .easeIn) case .easeInOut: options = [options, .curveEaseIn, .curveEaseOut] - timing = CAMediaTimingFunction(name: .easeOut) + timing = CAMediaTimingFunction(name: .easeInEaseOut) } autoreverses == true ? options.formUnion(.autoreverse) : options.subtract(.autoreverse) diff --git a/C4/UI/Timer.swift b/C4/UI/Timer.swift index 309e0c00..30d441af 100644 --- a/C4/UI/Timer.swift +++ b/C4/UI/Timer.swift @@ -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: .default) + RunLoop.main.add(t, forMode: .default) timer = t } diff --git a/C4/UI/UIImage+Color.swift b/C4/UI/UIImage+Color.swift index 142d5a13..9431e51f 100644 --- a/C4/UI/UIImage+Color.swift +++ b/C4/UI/UIImage+Color.swift @@ -25,7 +25,7 @@ public extension UIImage { /// - parameter color: The color to use when creating the image. /// - parameter size: The size of image to create. /// - returns: A UIImage filled with the specified color and whose dimensions equal the give size - class func createWithColor(_ color: UIColor, size: CGSize) -> UIImage { + class func createWithColor(_ color: UIColor, size: CGSize) -> UIImage { let rect = CGRect(x: 0, y: 0, width: size.width, height: size.height) UIGraphicsBeginImageContextWithOptions(size, false, 0) color.setFill() diff --git a/C4/UI/UIView+AddRemove.swift b/C4/UI/UIView+AddRemove.swift index 94b43cdf..731cde6a 100644 --- a/C4/UI/UIView+AddRemove.swift +++ b/C4/UI/UIView+AddRemove.swift @@ -72,9 +72,9 @@ extension UIView { /// - parameter subview: The subview to move to the back. public func sendToBack(_ subview: T?) { if let v = subview as? UIView { - self.sendSubviewToBack(v) + self.sendSubviewToBack(v) } else if let v = subview as? View { - self.sendSubviewToBack(v.view) + self.sendSubviewToBack(v.view) } else { fatalError("Can't operate on subview of class `\(type(of: subview))`") } @@ -85,9 +85,9 @@ extension UIView { /// - parameter subview: The subview to move to the front. public func bringToFront(_ subview: T?) { if let v = subview as? UIView { - self.bringSubviewToFront(v) + self.bringSubviewToFront(v) } else if let v = subview as? View { - self.bringSubviewToFront(v.view) + self.bringSubviewToFront(v.view) } else { fatalError("Can't operate on subview of class `\(type(of: subview))`") } diff --git a/C4/UI/UIViewController+C4View.swift b/C4/UI/UIViewController+C4View.swift index ac5d4d5c..cc4a9b32 100644 --- a/C4/UI/UIViewController+C4View.swift +++ b/C4/UI/UIViewController+C4View.swift @@ -38,7 +38,7 @@ private var canvasAssociationKey: UInt8 = 0 /// Where, `canvas` is essentially equal to `self.viewController.view`, keeping the interaction with a controller's main view consistent with using other View objects. public extension UIViewController { /// Returns a View object representation of the controller's `view` property. - var canvas: View { + var canvas: View { if let canvas = objc_getAssociatedObject(self, &canvasAssociationKey) as? View { return canvas } diff --git a/C4/UI/View+Animation.swift b/C4/UI/View+Animation.swift index be822b22..fffb3aed 100644 --- a/C4/UI/View+Animation.swift +++ b/C4/UI/View+Animation.swift @@ -40,7 +40,7 @@ public extension View { /// /// - parameter duration: The length of time in seconds for the animation to execute. /// - parameter animations: A block of code with specified animations to execute. - class func animate(duration: Double, animations: @escaping () -> Void) { + class func animate(duration: Double, animations: @escaping () -> Void) { UIView.animate(withDuration: duration, animations: animations) } @@ -50,7 +50,7 @@ public extension View { /// - parameter delay: The length of time in seconds to wait before executing the specified block of code. /// - parameter completion: A block of code to execute when the animation completes. /// - parameter animations: A block of code with specified animations to execute. - class func animate(duration: Double, delay: Double, animations: @escaping () -> Void, completion: ((Bool) -> Void)?) { + class func animate(duration: Double, delay: Double, animations: @escaping () -> Void, completion: ((Bool) -> Void)?) { UIView.animate(withDuration: duration, animations: animations, completion: completion) } @@ -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. - class func animate(duration: Double, delay: Double, options: UIView.AnimationOptions, animations: @escaping () -> Void, completion: ((Bool) -> Void)?) { + 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) } } diff --git a/C4/UI/View+Border.swift b/C4/UI/View+Border.swift index 85b85f14..1041ecc8 100644 --- a/C4/UI/View+Border.swift +++ b/C4/UI/View+Border.swift @@ -57,7 +57,7 @@ public extension View { /// ```` /// /// Assigning a new value to this will change the `borderWidth`, `borderColor` and `cornderRadius` of the receiver's layer. - var border: Border { + var border: Border { get { var border = Border() if let layer = layer { diff --git a/C4/UI/View+Render.swift b/C4/UI/View+Render.swift index 2cef4c63..5d961ef7 100644 --- a/C4/UI/View+Render.swift +++ b/C4/UI/View+Render.swift @@ -22,7 +22,7 @@ import UIKit public extension View { /// Creates a flattened image of the receiver and its subviews / layers. /// - returns: A new Image - @objc func render() -> Image? { + @objc func render() -> Image? { guard let l = layer else { print("Could not retrieve layer for current object: \(self)") return nil @@ -40,7 +40,7 @@ public extension Shape { /// Creates a flattened image of the receiver and its subviews / layers. /// This override takes into consideration the lineWidth of the receiver. /// - returns: A new Image - override func render() -> Image? { + override func render() -> Image? { var s = CGSize(size) var inset: CGFloat = 0 diff --git a/C4/UI/View+Shadow.swift b/C4/UI/View+Shadow.swift index 9dc67dea..cc014deb 100644 --- a/C4/UI/View+Shadow.swift +++ b/C4/UI/View+Shadow.swift @@ -79,7 +79,7 @@ public extension View { /// v.shadow = s /// canvas.add(v) /// ```` - var shadow: Shadow { + var shadow: Shadow { get { var shadow = Shadow() if let layer = layer { diff --git a/C4/UI/View.swift b/C4/UI/View.swift index 26b95f96..271d0163 100644 --- a/C4/UI/View.swift +++ b/C4/UI/View.swift @@ -375,9 +375,9 @@ open class View: NSObject { /// - parameter subview: The subview to move to the back. public func sendToBack(_ subview: T?) { if let v = subview as? UIView { - view.sendSubviewToBack(v) + view.sendSubviewToBack(v) } else if let v = subview as? View { - view.sendSubviewToBack(v.view) + view.sendSubviewToBack(v.view) } else { fatalError("Can't operate on subview of class `\(type(of: subview))`") } @@ -387,9 +387,9 @@ open class View: NSObject { /// - parameter subview: The subview to move to the front. public func bringToFront(_ subview: T?) { if let v = subview as? UIView { - view.bringSubviewToFront(v) + view.bringSubviewToFront(v) } else if let v = subview as? View { - view.bringSubviewToFront(v.view) + view.bringSubviewToFront(v.view) } else { fatalError("Can't operate on subview of class `\(type(of: subview))`") } diff --git a/C4/UI/ViewAnimation.swift b/C4/UI/ViewAnimation.swift index 99125a1d..15ec384d 100644 --- a/C4/UI/ViewAnimation.swift +++ b/C4/UI/ViewAnimation.swift @@ -95,19 +95,19 @@ public class ViewAnimation: Animation { public var timingFunction: CAMediaTimingFunction { switch curve { case .linear: - return CAMediaTimingFunction(name: CAMediaTimingFunctionName.linear) + return CAMediaTimingFunction(name: .linear) case .easeOut: - return CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeOut) + return CAMediaTimingFunction(name: .easeOut) case .easeIn: - return CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeIn) + return CAMediaTimingFunction(name: .easeIn) case .easeInOut: - return CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut) + return CAMediaTimingFunction(name: .easeInEaseOut) } } ///Options for animating views using block objects. - public var options: UIView.AnimationOptions { - var options: UIView.AnimationOptions = [.beginFromCurrentState] + public var options: UIView.AnimationOptions { + var options: UIView.AnimationOptions = [UIView.AnimationOptions.beginFromCurrentState] switch curve { case .linear: options = [options, .curveLinear] From 23f107d730c3c3c831fa59cc230c2a5c8b715cd8 Mon Sep 17 00:00:00 2001 From: Josh Billions Date: Fri, 29 Nov 2019 23:05:19 -0600 Subject: [PATCH 11/11] Remove migrator junk --- C4/UI/AudioPlayer.swift | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/C4/UI/AudioPlayer.swift b/C4/UI/AudioPlayer.swift index eeb64b81..de1efedb 100644 --- a/C4/UI/AudioPlayer.swift +++ b/C4/UI/AudioPlayer.swift @@ -48,7 +48,7 @@ public class AudioPlayer: NSObject, AVAudioPlayerDelegate { /// ```` public init?(_ name: String) { do { - try AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category(rawValue: convertFromAVAudioSessionCategory(AVAudioSession.Category.playback))) + try AVAudioSession.sharedInstance().setCategory(.playback) try AVAudioSession.sharedInstance().setActive(true) } catch { print("Couldn't set up AVAudioSession") @@ -248,8 +248,3 @@ public class AudioPlayer: NSObject, AVAudioPlayerDelegate { return Double(player.peakPower(forChannel: channel)) } } - -// Helper function inserted by Swift 4.2 migrator. -private func convertFromAVAudioSessionCategory(_ input: AVAudioSession.Category) -> String { - return input.rawValue -}