From 49e1748c7247a6aef9cb63519eb2614d813d9b32 Mon Sep 17 00:00:00 2001 From: Batuhan Saka Date: Wed, 17 Oct 2018 13:40:59 +0300 Subject: [PATCH 1/3] Deprecated unwrapped properties turned to safe. --- Spring/DesignableTabBarController.swift | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Spring/DesignableTabBarController.swift b/Spring/DesignableTabBarController.swift index f75fbcc..f6668de 100644 --- a/Spring/DesignableTabBarController.swift +++ b/Spring/DesignableTabBarController.swift @@ -47,7 +47,7 @@ import UIKit @IBInspectable var firstSelectedImage: UIImage? { didSet { if let image = firstSelectedImage { - var tabBarItems = self.tabBar.items as [UITabBarItem]! + var tabBarItems = self.tabBar.items tabBarItems?[0].selectedImage = image.withRenderingMode(UIImage.RenderingMode.alwaysTemplate) } } @@ -56,7 +56,7 @@ import UIKit @IBInspectable var secondSelectedImage: UIImage? { didSet { if let image = secondSelectedImage { - var tabBarItems = self.tabBar.items as [UITabBarItem]! + var tabBarItems = self.tabBar.items tabBarItems?[1].selectedImage = image.withRenderingMode(UIImage.RenderingMode.alwaysTemplate) } } @@ -65,7 +65,8 @@ import UIKit @IBInspectable var thirdSelectedImage: UIImage? { didSet { if let image = thirdSelectedImage { - var tabBarItems = self.tabBar.items as [UITabBarItem]! + + var tabBarItems = self.tabBar.items tabBarItems?[2].selectedImage = image.withRenderingMode(UIImage.RenderingMode.alwaysTemplate) } } @@ -74,7 +75,7 @@ import UIKit @IBInspectable var fourthSelectedImage: UIImage? { didSet { if let image = fourthSelectedImage { - var tabBarItems = self.tabBar.items as [UITabBarItem]! + var tabBarItems = self.tabBar.items tabBarItems?[3].selectedImage = image.withRenderingMode(UIImage.RenderingMode.alwaysTemplate) } } @@ -83,7 +84,7 @@ import UIKit @IBInspectable var fifthSelectedImage: UIImage? { didSet { if let image = fifthSelectedImage { - var tabBarItems = self.tabBar.items as [UITabBarItem]! + var tabBarItems = self.tabBar.items tabBarItems?[4].selectedImage = image.withRenderingMode(UIImage.RenderingMode.alwaysTemplate) } } @@ -92,7 +93,9 @@ import UIKit override func viewDidLoad() { super.viewDidLoad() - for item in self.tabBar.items as [UITabBarItem]! { + guard let items = self.tabBar.items else { return } + + for item in items { if let image = item.image { item.image = image.imageWithColor(tintColor: self.normalTint).withRenderingMode(UIImage.RenderingMode.alwaysOriginal) } From b54abce4b846c567fd67ffea50e944533a240bcc Mon Sep 17 00:00:00 2001 From: Batuhan Saka Date: Wed, 17 Oct 2018 13:42:18 +0300 Subject: [PATCH 2/3] Enum's syntax turned to Swift 4.2. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It'll be looks like, BEFORE |  AFTER .SlideLeft -> .slideLeft --- Spring/Spring.swift | 230 ++++++++++++++++++++++---------------------- 1 file changed, 115 insertions(+), 115 deletions(-) diff --git a/Spring/Spring.swift b/Spring/Spring.swift index cf86e1a..45df13c 100644 --- a/Spring/Spring.swift +++ b/Spring/Spring.swift @@ -104,97 +104,97 @@ public class Spring : NSObject { private var alpha: CGFloat { get { return view.alpha } set { view.alpha = newValue } } public enum AnimationPreset: String { - case SlideLeft = "slideLeft" - case SlideRight = "slideRight" - case SlideDown = "slideDown" - case SlideUp = "slideUp" - case SqueezeLeft = "squeezeLeft" - case SqueezeRight = "squeezeRight" - case SqueezeDown = "squeezeDown" - case SqueezeUp = "squeezeUp" - case FadeIn = "fadeIn" - case FadeOut = "fadeOut" - case FadeOutIn = "fadeOutIn" - case FadeInLeft = "fadeInLeft" - case FadeInRight = "fadeInRight" - case FadeInDown = "fadeInDown" - case FadeInUp = "fadeInUp" - case ZoomIn = "zoomIn" - case ZoomOut = "zoomOut" - case Fall = "fall" - case Shake = "shake" - case Pop = "pop" - case FlipX = "flipX" - case FlipY = "flipY" - case Morph = "morph" - case Squeeze = "squeeze" - case Flash = "flash" - case Wobble = "wobble" - case Swing = "swing" + case slideLeft = "slideLeft" + case slideRight = "slideRight" + case slideDown = "slideDown" + case slideUp = "slideUp" + case squeezeLeft = "squeezeLeft" + case squeezeRight = "squeezeRight" + case squeezeDown = "squeezeDown" + case squeezeUp = "squeezeUp" + case fadeIn = "fadeIn" + case fadeOut = "fadeOut" + case fadeOutIn = "fadeOutIn" + case fadeInLeft = "fadeInLeft" + case fadeInRight = "fadeInRight" + case fadeInDown = "fadeInDown" + case fadeInUp = "fadeInUp" + case zoomIn = "zoomIn" + case zoomOut = "zoomOut" + case fall = "fall" + case shake = "shake" + case pop = "pop" + case flipX = "flipX" + case flipY = "flipY" + case morph = "morph" + case squeeze = "squeeze" + case flash = "flash" + case wobble = "wobble" + case swing = "swing" } public enum AnimationCurve: String { - case EaseIn = "easeIn" - case EaseOut = "easeOut" - case EaseInOut = "easeInOut" - case Linear = "linear" - case Spring = "spring" - case EaseInSine = "easeInSine" - case EaseOutSine = "easeOutSine" - case EaseInOutSine = "easeInOutSine" - case EaseInQuad = "easeInQuad" - case EaseOutQuad = "easeOutQuad" - case EaseInOutQuad = "easeInOutQuad" - case EaseInCubic = "easeInCubic" - case EaseOutCubic = "easeOutCubic" - case EaseInOutCubic = "easeInOutCubic" - case EaseInQuart = "easeInQuart" - case EaseOutQuart = "easeOutQuart" - case EaseInOutQuart = "easeInOutQuart" - case EaseInQuint = "easeInQuint" - case EaseOutQuint = "easeOutQuint" - case EaseInOutQuint = "easeInOutQuint" - case EaseInExpo = "easeInExpo" - case EaseOutExpo = "easeOutExpo" - case EaseInOutExpo = "easeInOutExpo" - case EaseInCirc = "easeInCirc" - case EaseOutCirc = "easeOutCirc" - case EaseInOutCirc = "easeInOutCirc" - case EaseInBack = "easeInBack" - case EaseOutBack = "easeOutBack" - case EaseInOutBack = "easeInOutBack" + case easeIn = "easeIn" + case easeOut = "easeOut" + case easeInOut = "easeInOut" + case linear = "linear" + case spring = "spring" + case easeInSine = "easeInSine" + case easeOutSine = "easeOutSine" + case easeInOutSine = "easeInOutSine" + case easeInQuad = "easeInQuad" + case easeOutQuad = "easeOutQuad" + case easeInOutQuad = "easeInOutQuad" + case easeInCubic = "easeInCubic" + case easeOutCubic = "easeOutCubic" + case easeInOutCubic = "easeInOutCubic" + case easeInQuart = "easeInQuart" + case easeOutQuart = "easeOutQuart" + case easeInOutQuart = "easeInOutQuart" + case easeInQuint = "easeInQuint" + case easeOutQuint = "easeOutQuint" + case easeInOutQuint = "easeInOutQuint" + case easeInExpo = "easeInExpo" + case easeOutExpo = "easeOutExpo" + case easeInOutExpo = "easeInOutExpo" + case easeInCirc = "easeInCirc" + case easeOutCirc = "easeOutCirc" + case easeInOutCirc = "easeInOutCirc" + case easeInBack = "easeInBack" + case easeOutBack = "easeOutBack" + case easeInOutBack = "easeInOutBack" } func animatePreset() { alpha = 0.99 if let animation = AnimationPreset(rawValue: animation) { switch animation { - case .SlideLeft: + case .slideLeft: x = 300*force - case .SlideRight: + case .slideRight: x = -300*force - case .SlideDown: + case .slideDown: y = -300*force - case .SlideUp: + case .slideUp: y = 300*force - case .SqueezeLeft: + case .squeezeLeft: x = 300 scaleX = 3*force - case .SqueezeRight: + case .squeezeRight: x = -300 scaleX = 3*force - case .SqueezeDown: + case .squeezeDown: y = -300 scaleY = 3*force - case .SqueezeUp: + case .squeezeUp: y = 300 scaleY = 3*force - case .FadeIn: + case .fadeIn: opacity = 0 - case .FadeOut: + case .fadeOut: animateFrom = false opacity = 0 - case .FadeOutIn: + case .fadeOutIn: let animation = CABasicAnimation() animation.keyPath = "opacity" animation.fromValue = 1 @@ -204,32 +204,32 @@ public class Spring : NSObject { animation.beginTime = CACurrentMediaTime() + CFTimeInterval(delay) animation.autoreverses = true layer.add(animation, forKey: "fade") - case .FadeInLeft: + case .fadeInLeft: opacity = 0 x = 300*force - case .FadeInRight: + case .fadeInRight: x = -300*force opacity = 0 - case .FadeInDown: + case .fadeInDown: y = -300*force opacity = 0 - case .FadeInUp: + case .fadeInUp: y = 300*force opacity = 0 - case .ZoomIn: + case .zoomIn: opacity = 0 scaleX = 2*force scaleY = 2*force - case .ZoomOut: + case .zoomOut: animateFrom = false opacity = 0 scaleX = 2*force scaleY = 2*force - case .Fall: + case .fall: animateFrom = false rotate = 15 * CGFloat(CGFloat.pi/180) y = 600*force - case .Shake: + case .shake: let animation = CAKeyframeAnimation() animation.keyPath = "position.x" animation.values = [0, 30*force, -30*force, 30*force, 0] @@ -240,7 +240,7 @@ public class Spring : NSObject { animation.repeatCount = repeatCount animation.beginTime = CACurrentMediaTime() + CFTimeInterval(delay) layer.add(animation, forKey: "shake") - case .Pop: + case .pop: let animation = CAKeyframeAnimation() animation.keyPath = "transform.scale" animation.values = [0, 0.2*force, -0.2*force, 0.2*force, 0] @@ -251,7 +251,7 @@ public class Spring : NSObject { animation.repeatCount = repeatCount animation.beginTime = CACurrentMediaTime() + CFTimeInterval(delay) layer.add(animation, forKey: "pop") - case .FlipX: + case .flipX: rotate = 0 scaleX = 1 scaleY = 1 @@ -268,7 +268,7 @@ public class Spring : NSObject { animation.beginTime = CACurrentMediaTime() + CFTimeInterval(delay) animation.timingFunction = getTimingFunction(curve: curve) layer.add(animation, forKey: "3d") - case .FlipY: + case .flipY: var perspective = CATransform3DIdentity perspective.m34 = -1.0 / layer.frame.size.width/2 @@ -283,7 +283,7 @@ public class Spring : NSObject { animation.beginTime = CACurrentMediaTime() + CFTimeInterval(delay) animation.timingFunction = getTimingFunction(curve: curve) layer.add(animation, forKey: "3d") - case .Morph: + case .morph: let morphX = CAKeyframeAnimation() morphX.keyPath = "transform.scale.x" morphX.values = [1, 1.3*force, 0.7, 1.3*force, 1] @@ -303,7 +303,7 @@ public class Spring : NSObject { morphY.repeatCount = repeatCount morphY.beginTime = CACurrentMediaTime() + CFTimeInterval(delay) layer.add(morphY, forKey: "morphY") - case .Squeeze: + case .squeeze: let morphX = CAKeyframeAnimation() morphX.keyPath = "transform.scale.x" morphX.values = [1, 1.5*force, 0.5, 1.5*force, 1] @@ -323,7 +323,7 @@ public class Spring : NSObject { morphY.repeatCount = repeatCount morphY.beginTime = CACurrentMediaTime() + CFTimeInterval(delay) layer.add(morphY, forKey: "morphY") - case .Flash: + case .flash: let animation = CABasicAnimation() animation.keyPath = "opacity" animation.fromValue = 1 @@ -333,7 +333,7 @@ public class Spring : NSObject { animation.autoreverses = true animation.beginTime = CACurrentMediaTime() + CFTimeInterval(delay) layer.add(animation, forKey: "flash") - case .Wobble: + case .wobble: let animation = CAKeyframeAnimation() animation.keyPath = "transform.rotation" animation.values = [0, 0.3*force, -0.3*force, 0.3*force, 0] @@ -353,7 +353,7 @@ public class Spring : NSObject { x.repeatCount = repeatCount x.beginTime = CACurrentMediaTime() + CFTimeInterval(delay) layer.add(x, forKey: "x") - case .Swing: + case .swing: let animation = CAKeyframeAnimation() animation.keyPath = "transform.rotation" animation.values = [0, 0.3*force, -0.3*force, 0.3*force, 0] @@ -370,35 +370,35 @@ public class Spring : NSObject { func getTimingFunction(curve: String) -> CAMediaTimingFunction { if let curve = AnimationCurve(rawValue: curve) { switch curve { - case .EaseIn: return CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeIn) - case .EaseOut: return CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeOut) - case .EaseInOut: return CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut) - case .Linear: return CAMediaTimingFunction(name: CAMediaTimingFunctionName.linear) - case .Spring: return CAMediaTimingFunction(controlPoints: 0.5, 1.1+Float(force/3), 1, 1) - case .EaseInSine: return CAMediaTimingFunction(controlPoints: 0.47, 0, 0.745, 0.715) - case .EaseOutSine: return CAMediaTimingFunction(controlPoints: 0.39, 0.575, 0.565, 1) - case .EaseInOutSine: return CAMediaTimingFunction(controlPoints: 0.445, 0.05, 0.55, 0.95) - case .EaseInQuad: return CAMediaTimingFunction(controlPoints: 0.55, 0.085, 0.68, 0.53) - case .EaseOutQuad: return CAMediaTimingFunction(controlPoints: 0.25, 0.46, 0.45, 0.94) - case .EaseInOutQuad: return CAMediaTimingFunction(controlPoints: 0.455, 0.03, 0.515, 0.955) - case .EaseInCubic: return CAMediaTimingFunction(controlPoints: 0.55, 0.055, 0.675, 0.19) - case .EaseOutCubic: return CAMediaTimingFunction(controlPoints: 0.215, 0.61, 0.355, 1) - case .EaseInOutCubic: return CAMediaTimingFunction(controlPoints: 0.645, 0.045, 0.355, 1) - case .EaseInQuart: return CAMediaTimingFunction(controlPoints: 0.895, 0.03, 0.685, 0.22) - case .EaseOutQuart: return CAMediaTimingFunction(controlPoints: 0.165, 0.84, 0.44, 1) - case .EaseInOutQuart: return CAMediaTimingFunction(controlPoints: 0.77, 0, 0.175, 1) - case .EaseInQuint: return CAMediaTimingFunction(controlPoints: 0.755, 0.05, 0.855, 0.06) - case .EaseOutQuint: return CAMediaTimingFunction(controlPoints: 0.23, 1, 0.32, 1) - case .EaseInOutQuint: return CAMediaTimingFunction(controlPoints: 0.86, 0, 0.07, 1) - case .EaseInExpo: return CAMediaTimingFunction(controlPoints: 0.95, 0.05, 0.795, 0.035) - case .EaseOutExpo: return CAMediaTimingFunction(controlPoints: 0.19, 1, 0.22, 1) - case .EaseInOutExpo: return CAMediaTimingFunction(controlPoints: 1, 0, 0, 1) - case .EaseInCirc: return CAMediaTimingFunction(controlPoints: 0.6, 0.04, 0.98, 0.335) - case .EaseOutCirc: return CAMediaTimingFunction(controlPoints: 0.075, 0.82, 0.165, 1) - case .EaseInOutCirc: return CAMediaTimingFunction(controlPoints: 0.785, 0.135, 0.15, 0.86) - case .EaseInBack: return CAMediaTimingFunction(controlPoints: 0.6, -0.28, 0.735, 0.045) - case .EaseOutBack: return CAMediaTimingFunction(controlPoints: 0.175, 0.885, 0.32, 1.275) - case .EaseInOutBack: return CAMediaTimingFunction(controlPoints: 0.68, -0.55, 0.265, 1.55) + case .easeIn: return CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeIn) + case .easeOut: return CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeOut) + case .easeInOut: return CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut) + case .linear: return CAMediaTimingFunction(name: CAMediaTimingFunctionName.linear) + case .spring: return CAMediaTimingFunction(controlPoints: 0.5, 1.1+Float(force/3), 1, 1) + case .easeInSine: return CAMediaTimingFunction(controlPoints: 0.47, 0, 0.745, 0.715) + case .easeOutSine: return CAMediaTimingFunction(controlPoints: 0.39, 0.575, 0.565, 1) + case .easeInOutSine: return CAMediaTimingFunction(controlPoints: 0.445, 0.05, 0.55, 0.95) + case .easeInQuad: return CAMediaTimingFunction(controlPoints: 0.55, 0.085, 0.68, 0.53) + case .easeOutQuad: return CAMediaTimingFunction(controlPoints: 0.25, 0.46, 0.45, 0.94) + case .easeInOutQuad: return CAMediaTimingFunction(controlPoints: 0.455, 0.03, 0.515, 0.955) + case .easeInCubic: return CAMediaTimingFunction(controlPoints: 0.55, 0.055, 0.675, 0.19) + case .easeOutCubic: return CAMediaTimingFunction(controlPoints: 0.215, 0.61, 0.355, 1) + case .easeInOutCubic: return CAMediaTimingFunction(controlPoints: 0.645, 0.045, 0.355, 1) + case .easeInQuart: return CAMediaTimingFunction(controlPoints: 0.895, 0.03, 0.685, 0.22) + case .easeOutQuart: return CAMediaTimingFunction(controlPoints: 0.165, 0.84, 0.44, 1) + case .easeInOutQuart: return CAMediaTimingFunction(controlPoints: 0.77, 0, 0.175, 1) + case .easeInQuint: return CAMediaTimingFunction(controlPoints: 0.755, 0.05, 0.855, 0.06) + case .easeOutQuint: return CAMediaTimingFunction(controlPoints: 0.23, 1, 0.32, 1) + case .easeInOutQuint: return CAMediaTimingFunction(controlPoints: 0.86, 0, 0.07, 1) + case .easeInExpo: return CAMediaTimingFunction(controlPoints: 0.95, 0.05, 0.795, 0.035) + case .easeOutExpo: return CAMediaTimingFunction(controlPoints: 0.19, 1, 0.22, 1) + case .easeInOutExpo: return CAMediaTimingFunction(controlPoints: 1, 0, 0, 1) + case .easeInCirc: return CAMediaTimingFunction(controlPoints: 0.6, 0.04, 0.98, 0.335) + case .easeOutCirc: return CAMediaTimingFunction(controlPoints: 0.075, 0.82, 0.165, 1) + case .easeInOutCirc: return CAMediaTimingFunction(controlPoints: 0.785, 0.135, 0.15, 0.86) + case .easeInBack: return CAMediaTimingFunction(controlPoints: 0.6, -0.28, 0.735, 0.045) + case .easeOutBack: return CAMediaTimingFunction(controlPoints: 0.175, 0.885, 0.32, 1.275) + case .easeInOutBack: return CAMediaTimingFunction(controlPoints: 0.68, -0.55, 0.265, 1.55) } } return CAMediaTimingFunction(name: CAMediaTimingFunctionName.default) @@ -407,9 +407,9 @@ public class Spring : NSObject { func getAnimationOptions(curve: String) -> UIView.AnimationOptions { if let curve = AnimationCurve(rawValue: curve) { switch curve { - case .EaseIn: return UIView.AnimationOptions.curveEaseIn - case .EaseOut: return UIView.AnimationOptions.curveEaseOut - case .EaseInOut: return UIView.AnimationOptions() + case .easeIn: return UIView.AnimationOptions.curveEaseIn + case .easeOut: return UIView.AnimationOptions.curveEaseOut + case .easeInOut: return UIView.AnimationOptions() default: break } } From 29e652fb77f9a4038fda4dbddd4e4de0c0599101 Mon Sep 17 00:00:00 2001 From: Batuhan Saka Date: Wed, 17 Oct 2018 13:42:58 +0300 Subject: [PATCH 3/3] AnimationCurve & Preset enums turned to new syntax. --- SpringApp/SpringViewController.swift | 110 +++++++++++++-------------- 1 file changed, 55 insertions(+), 55 deletions(-) diff --git a/SpringApp/SpringViewController.swift b/SpringApp/SpringViewController.swift index 6a4ea1b..a007581 100644 --- a/SpringApp/SpringViewController.swift +++ b/SpringApp/SpringViewController.swift @@ -117,64 +117,64 @@ class SpringViewController: UIViewController, UIPickerViewDelegate, UIPickerView } let animations: [Spring.AnimationPreset] = [ - .Shake, - .Pop, - .Morph, - .Squeeze, - .Wobble, - .Swing, - .FlipX, - .FlipY, - .Fall, - .SqueezeLeft, - .SqueezeRight, - .SqueezeDown, - .SqueezeUp, - .SlideLeft, - .SlideRight, - .SlideDown, - .SlideUp, - .FadeIn, - .FadeOut, - .FadeInLeft, - .FadeInRight, - .FadeInDown, - .FadeInUp, - .ZoomIn, - .ZoomOut, - .Flash + .shake, + .pop, + .morph, + .squeeze, + .wobble, + .swing, + .flipX, + .flipY, + .fall, + .squeezeLeft, + .squeezeRight, + .squeezeDown, + .squeezeUp, + .slideLeft, + .slideRight, + .slideDown, + .slideUp, + .fadeIn, + .fadeOut, + .fadeInLeft, + .fadeInRight, + .fadeInDown, + .fadeInUp, + .zoomIn, + .zoomOut, + .flash ] var animationCurves: [Spring.AnimationCurve] = [ - .EaseIn, - .EaseOut, - .EaseInOut, - .Linear, - .Spring, - .EaseInSine, - .EaseOutSine, - .EaseInOutSine, - .EaseInQuad, - .EaseOutQuad, - .EaseInOutQuad, - .EaseInCubic, - .EaseOutCubic, - .EaseInOutCubic, - .EaseInQuart, - .EaseOutQuart, - .EaseInOutQuart, - .EaseInQuint, - .EaseOutQuint, - .EaseInOutQuint, - .EaseInExpo, - .EaseOutExpo, - .EaseInOutExpo, - .EaseInCirc, - .EaseOutCirc, - .EaseInOutCirc, - .EaseInBack, - .EaseOutBack, - .EaseInOutBack + .easeIn, + .easeOut, + .easeInOut, + .linear, + .spring, + .easeInSine, + .easeOutSine, + .easeInOutSine, + .easeInQuad, + .easeOutQuad, + .easeInOutQuad, + .easeInCubic, + .easeOutCubic, + .easeInOutCubic, + .easeInQuart, + .easeOutQuart, + .easeInOutQuart, + .easeInQuint, + .easeOutQuint, + .easeInOutQuint, + .easeInExpo, + .easeOutExpo, + .easeInOutExpo, + .easeInCirc, + .easeOutCirc, + .easeInOutCirc, + .easeInBack, + .easeOutBack, + .easeInOutBack ] override func viewDidLoad() {