Skip to content

Commit

Permalink
Merge pull request #15 from Yalantis/feature/swift5.2
Browse files Browse the repository at this point in the history
Feature/swift5.2
  • Loading branch information
PravdaEvgen authored Apr 9, 2020
2 parents 6756057 + 6a6de45 commit 141b139
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 51 deletions.
2 changes: 1 addition & 1 deletion Demo/DemoProject/ViewController/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ViewController: UIViewController {

eatFitController.dataSource = self
eatFitController.view.frame = view.frame
addChildViewController(eatFitController)
addChild(eatFitController)
view.yal_addSubview(eatFitController.view, options: .overlay)
}
}
Expand Down
10 changes: 6 additions & 4 deletions Demo/EatFit Demo Project.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -301,13 +301,13 @@
TargetAttributes = {
5B66836B1B94529400416AC3 = {
CreatedOnToolsVersion = 6.4;
LastSwiftMigration = 0800;
LastSwiftMigration = 1140;
};
};
};
buildConfigurationList = 5B6683671B94529400416AC3 /* Build configuration list for PBXProject "EatFit Demo Project" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
Expand Down Expand Up @@ -486,7 +486,8 @@
PRODUCT_NAME = "EatFit Demo Project";
SWIFT_OBJC_BRIDGING_HEADER = "";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -500,7 +501,8 @@
PRODUCT_BUNDLE_IDENTIFIER = "YAL.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "EatFit Demo Project";
SWIFT_OBJC_BRIDGING_HEADER = "";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand Down
9 changes: 6 additions & 3 deletions EatFit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,11 @@
};
buildConfigurationList = C52988751D45E2620058C829 /* Build configuration list for PBXProject "EatFit" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
mainGroup = C52988711D45E2620058C829;
productRefGroup = C529887C1D45E2620058C829 /* Products */;
Expand Down Expand Up @@ -336,6 +337,7 @@
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand Down Expand Up @@ -377,6 +379,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 9.3;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
Expand All @@ -397,7 +400,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.yalantis.EatFit;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -414,7 +417,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.yalantis.EatFit;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand Down
29 changes: 20 additions & 9 deletions EatFit/Extensions/UILabel+Animation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extension UILabel {

func animateAdding(_ duration: Double) {
if let text = text {
iterateAdding(text as NSString, index: 0, delay: duration / Double(text.characters.count))
iterateAdding(text as NSString, index: 0, delay: duration / Double(text.count))
}
}

Expand All @@ -38,7 +38,7 @@ extension UILabel {

textColor = UIColor.clear
DispatchQueue.main.asyncAfter(deadline: time) { () -> Void in
self.iterateAlpha(text as NSString, index: 0, delay: duration / Double(text.characters.count), font: self.font, color: originalFontColor!)
self.iterateAlpha(text as NSString, index: 0, delay: duration / Double(text.count), font: self.font, color: originalFontColor!)
}
}
}
Expand All @@ -47,22 +47,22 @@ extension UILabel {
let substringToShow = text.substring(to: index);
let substringToHide = text.substring(from: index);

let showAttrs = [NSFontAttributeName: font,
NSForegroundColorAttributeName: color]
let showString = NSAttributedString(string: substringToShow, attributes: showAttrs)
let showAttrs = [convertFromNSAttributedStringKey(NSAttributedString.Key.font): font,
convertFromNSAttributedStringKey(NSAttributedString.Key.foregroundColor): color]
let showString = NSAttributedString(string: substringToShow, attributes: convertToOptionalNSAttributedStringKeyDictionary(showAttrs))

let hideAttrs = [NSFontAttributeName: font,
NSForegroundColorAttributeName: UIColor.clear]
let hideAttrs = [convertFromNSAttributedStringKey(NSAttributedString.Key.font): font,
convertFromNSAttributedStringKey(NSAttributedString.Key.foregroundColor): UIColor.clear]

let hideString = NSAttributedString(string: substringToHide, attributes: hideAttrs)
let hideString = NSAttributedString(string: substringToHide, attributes: convertToOptionalNSAttributedStringKeyDictionary(hideAttrs))

let result = NSMutableAttributedString()
result.append(showString)
result.append(hideString)

self.attributedText = result

if substringToHide.characters.count != 0 {
if substringToHide.count != 0 {
let time = DispatchTime.now() + Double(Int64(delay * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC)

DispatchQueue.main.asyncAfter(deadline: time) { () -> Void in
Expand All @@ -71,3 +71,14 @@ extension UILabel {
}
}
}

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

// Helper function inserted by Swift 4.2 migrator.
fileprivate func convertToOptionalNSAttributedStringKeyDictionary(_ input: [String: Any]?) -> [NSAttributedString.Key: Any]? {
guard let input = input else { return nil }
return Dictionary(uniqueKeysWithValues: input.map { key, value in (NSAttributedString.Key(rawValue: key), value)})
}
2 changes: 1 addition & 1 deletion EatFit/Extensions/UIView+YALAppearance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import UIKit

private typealias SubviewTreeModifier = ((Void) -> UIView)
private typealias SubviewTreeModifier = (() -> UIView)

public struct AppearanceOptions: OptionSet {
public let rawValue: UInt
Expand Down
2 changes: 1 addition & 1 deletion EatFit/Various/Tween/Tween.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class TweenLayer: CALayer {
var from: CGFloat = 0
var to: CGFloat = 0
var tweenDuration: TimeInterval = 0
var timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
var timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.linear)
var delay: TimeInterval = 0

override class func needsDisplay(forKey event: String) -> Bool {
Expand Down
18 changes: 9 additions & 9 deletions EatFit/Vendors/YALPageController/YALPageController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ class YALPageController: NSObject {
return
}

let currentIndex = viewControllers.index(of: lastViewController)
let index = viewControllers.index(of: viewController)
let currentIndex = viewControllers.firstIndex(of: lastViewController)
let index = viewControllers.firstIndex(of: viewController)

if currentIndex == index {
return
}

let direction: UIPageViewControllerNavigationDirection = index > currentIndex ? .forward : .reverse
let direction: UIPageViewController.NavigationDirection = index > currentIndex ? .forward : .reverse
pageViewController.setViewControllers(
[viewController],
direction: direction,
Expand Down Expand Up @@ -99,7 +99,7 @@ class YALPageController: NSObject {
completion: nil
)

guard let pageIndex = viewControllers.index(of: firstViewController) else {
guard let pageIndex = viewControllers.firstIndex(of: firstViewController) else {
return
}

Expand All @@ -114,8 +114,8 @@ class YALPageController: NSObject {
self.pageViewController = pageViewController

self.pageViewController.view.subviews.forEach { view in
if view.isKind(of: UIScrollView.self) {
scrollView = view as! UIScrollView
if let view = view as? UIScrollView {
scrollView = view
}
}
}
Expand All @@ -134,7 +134,7 @@ class YALPageController: NSObject {
extension YALPageController: UIPageViewControllerDataSource {

func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {
guard let index = viewControllers.index(of: viewController) else {
guard let index = viewControllers.firstIndex(of: viewController) else {
return nil
}

Expand All @@ -147,7 +147,7 @@ extension YALPageController: UIPageViewControllerDataSource {


func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {
guard let index = viewControllers.index(of: viewController) else {
guard let index = viewControllers.firstIndex(of: viewController) else {
return nil
}

Expand All @@ -170,7 +170,7 @@ extension YALPageController: UIPageViewControllerDelegate {

if let lastViewController = pageViewController.viewControllers?.last , lastViewController != previousViewControllers.last {

if let lastIndex = viewControllers.index(of: lastViewController) {
if let lastIndex = viewControllers.firstIndex(of: lastViewController) {
didFinishTransition?(
pageViewController,
lastViewController,
Expand Down
4 changes: 2 additions & 2 deletions EatFit/ViewController/Slide/EatFitSlideViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class EatFitSlideViewController: UIViewController {

var logoImage: UIImage = UIImage() {
didSet {
dropView.logo = logoImage.withRenderingMode(UIImageRenderingMode.alwaysTemplate)
dropView.logo = logoImage.withRenderingMode(UIImage.RenderingMode.alwaysTemplate)
}
}

Expand Down Expand Up @@ -80,7 +80,7 @@ class EatFitSlideViewController: UIViewController {

func animatePercentageLabel (delay: TimeInterval) {
let tween = Tween(object: percentageLabel, key: "text", to: CGFloat(percentage))
tween.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut)
tween.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeOut)
tween.mapper = { value in
return value == 0 ? "" : String(format: "%0.f%%", value)
}
Expand Down
20 changes: 10 additions & 10 deletions EatFit/Views/DropView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class DropView: UIView {
let animation = CABasicAnimation(keyPath: "transform.translation.y")
animation.duration = 0.05
animation.toValue = dropFall.toValue
animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseIn)
animation.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeIn)
return animation
}()

Expand All @@ -102,7 +102,7 @@ class DropView: UIView {
animation.repeatCount = 1.0
animation.fromValue = 1.0
animation.toValue = 0.6
animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
animation.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.linear)
animation.autoreverses = true
animation.isRemovedOnCompletion = false
return animation
Expand All @@ -122,10 +122,10 @@ class DropView: UIView {
animation.repeatCount = 1.0
animation.fromValue = 1.0
animation.toValue = NSValue(caTransform3D: CATransform3DMakeScale(0.0, 0.0, 0.0))
animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
animation.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.linear)
animation.autoreverses = false
animation.isRemovedOnCompletion = false
animation.fillMode = kCAFillModeForwards
animation.fillMode = CAMediaTimingFillMode.forwards
return animation
}()

Expand All @@ -136,9 +136,9 @@ class DropView: UIView {
animation.beginTime = CACurrentMediaTime() + delay
animation.duration = dropDisappear.duration
animation.toValue = 18.0
animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
animation.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.linear)
animation.isRemovedOnCompletion = false
animation.fillMode = kCAFillModeForwards
animation.fillMode = CAMediaTimingFillMode.forwards
return animation
}()
drop.add(dropMove, forKey: "moveDown")
Expand All @@ -150,10 +150,10 @@ class DropView: UIView {
animation.repeatCount = 1.0
animation.fromValue = NSValue(caTransform3D:CATransform3DMakeScale(0.0, 0.0, 0.0))
animation.toValue = NSValue(caTransform3D:CATransform3DMakeScale(2.0, 2.0, 2.0))
animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
animation.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.linear)
animation.autoreverses = false
animation.isRemovedOnCompletion = false
animation.fillMode = kCAFillModeForwards
animation.fillMode = CAMediaTimingFillMode.forwards
return animation
}()
logoImageView.layer.add(imageShow, forKey: "show")
Expand All @@ -163,9 +163,9 @@ class DropView: UIView {
animation.beginTime = CACurrentMediaTime() + delay
animation.duration = imageShow.duration
animation.toValue = 18.0
animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
animation.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.linear)
animation.isRemovedOnCompletion = false
animation.fillMode = kCAFillModeForwards
animation.fillMode = CAMediaTimingFillMode.forwards
return animation
}()
logoImageView.layer.add(imageMove, forKey: "move")
Expand Down
14 changes: 7 additions & 7 deletions EatFit/Views/RoundChartView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class RoundChartView: UIView {
fileprivate let greyChart: CAShapeLayer = {
let circle: CAShapeLayer = CAShapeLayer()
circle.position = .zero
circle.lineCap = kCALineCapRound
circle.lineCap = CAShapeLayerLineCap.round
circle.fillColor = UIColor.clear.cgColor
circle.strokeColor = UIColor(red: 0.9, green: 0.9, blue: 0.9, alpha: 1.0).cgColor
circle.strokeEnd = 0
Expand All @@ -41,7 +41,7 @@ class RoundChartView: UIView {
fileprivate let colorChart: CAShapeLayer = {
let circle: CAShapeLayer = CAShapeLayer()
circle.position = .zero
circle.lineCap = kCALineCapRound
circle.lineCap = CAShapeLayerLineCap.round
circle.fillColor = UIColor.clear.cgColor
circle.strokeEnd = 0
circle.strokeColor = UIColor.red.cgColor
Expand Down Expand Up @@ -72,24 +72,24 @@ class RoundChartView: UIView {
let splashDuration: TimeInterval = 0.2
let toValue: Int = min(100, percentage + 10)

let splash: CABasicAnimation = animation(percentage: toValue, duration: splashDuration, timingFunction: CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut))
let splash: CABasicAnimation = animation(percentage: toValue, duration: splashDuration, timingFunction: CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeOut))
splash.beginTime = colorChartShow.beginTime + colorChartShow.duration + showTime

let colorHide: CABasicAnimation = animation(percentage: -1, duration: 0.3, timingFunction: CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut))
let colorHide: CABasicAnimation = animation(percentage: -1, duration: 0.3, timingFunction: CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeOut))
colorHide.beginTime = splash.beginTime + splash.duration

let colorGroup: CAAnimationGroup = CAAnimationGroup()
colorGroup.duration = delay + colorChartShow.duration + showTime + splashDuration + colorHide.duration
colorGroup.animations = [colorChartShow, splash, colorHide]
colorGroup.fillMode = kCAFillModeForwards
colorGroup.fillMode = CAMediaTimingFillMode.forwards
colorGroup.isRemovedOnCompletion = false

colorChart.add(colorGroup, forKey: "show")

let greyChartShow = animation(percentage: 100, duration: 0.6, timingFunction:easeOut)
greyChartShow.beginTime = colorChartShow.beginTime

let greyChartHide = animation(percentage: -1, duration: 0.3, timingFunction: CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut));
let greyChartHide = animation(percentage: -1, duration: 0.3, timingFunction: CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeOut));
greyChartHide.beginTime = colorHide.beginTime

let greyGroup: CAAnimationGroup = CAAnimationGroup()
Expand All @@ -109,7 +109,7 @@ class RoundChartView: UIView {
animation.duration = duration
animation.repeatCount = 1
animation.toValue = Float(percentage) / 100
animation.fillMode = kCAFillModeForwards
animation.fillMode = CAMediaTimingFillMode.forwards
animation.isRemovedOnCompletion = false
animation.timingFunction = timingFunction

Expand Down
2 changes: 1 addition & 1 deletion EatFit/Views/SlideLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class SlideLabelView: UIView {
labelShift.duration = 0.7
labelShift.fromValue = 50
labelShift.toValue = 0
labelShift.timingFunction = CAMediaTimingFunction(name:kCAMediaTimingFunctionEaseOut)
labelShift.timingFunction = CAMediaTimingFunction(name:CAMediaTimingFunctionName.easeOut)
return labelShift
}()
label.layer.add(labelShift, forKey: "shift")
Expand Down
Loading

0 comments on commit 141b139

Please sign in to comment.