Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift 4.2 conversion #307

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Spring/AsyncButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class AsyncButton: UIButton {
private var placeholderImage = [UInt:UIImage]()


public func setImageURL(url: NSURL?, placeholderImage placeholder:UIImage?, forState state:UIControlState) {
public func setImageURL(url: NSURL?, placeholderImage placeholder:UIImage?, forState state:UIControl.State) {

imageURL[state.rawValue] = url
placeholderImage[state.rawValue] = placeholder
Expand Down
2 changes: 1 addition & 1 deletion Spring/AutoTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class AutoTextView: UITextView {
get {
var size = self.sizeThatFits(CGSize(width: self.frame.size.width, height: CGFloat.greatestFiniteMagnitude))
size.width = self.frame.size.width
if text.length == 0 {
if text.count == 0 {
size.height = 0
}

Expand Down
2 changes: 1 addition & 1 deletion Spring/BlurView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import UIKit

public func insertBlurView (view: UIView, style: UIBlurEffectStyle) -> UIVisualEffectView {
public func insertBlurView (view: UIView, style: UIBlurEffect.Style) -> UIVisualEffectView {
view.backgroundColor = UIColor.clear

let blurEffect = UIBlurEffect(style: style)
Expand Down
4 changes: 2 additions & 2 deletions Spring/DesignableLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ import UIKit
paragraphStyle.lineSpacing = lineHeight

let attributedString = NSMutableAttributedString(string: text)
attributedString.addAttribute(NSAttributedStringKey.paragraphStyle, value: paragraphStyle, range: NSMakeRange(0, attributedString.length))
attributedString.addAttribute(NSAttributedStringKey.font, value: font!, range: NSMakeRange(0, attributedString.length))
attributedString.addAttribute(NSAttributedString.Key.paragraphStyle, value: paragraphStyle, range: NSMakeRange(0, attributedString.length))
attributedString.addAttribute(NSAttributedString.Key.font, value: font!, range: NSMakeRange(0, attributedString.length))

self.attributedText = attributedString
}
Expand Down
35 changes: 15 additions & 20 deletions Spring/DesignableTabBarController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,74 +27,69 @@ import UIKit
@IBInspectable var normalTint: UIColor = UIColor.clear {
didSet {
UITabBar.appearance().tintColor = normalTint
UITabBarItem.appearance().setTitleTextAttributes([NSAttributedStringKey.foregroundColor: normalTint], for: UIControlState())
UITabBarItem.appearance().setTitleTextAttributes([NSAttributedString.Key.foregroundColor: normalTint], for: UIControl.State())
}
}

@IBInspectable var selectedTint: UIColor = UIColor.clear {
didSet {
UITabBar.appearance().tintColor = selectedTint
UITabBarItem.appearance().setTitleTextAttributes([NSAttributedStringKey.foregroundColor: selectedTint], for:UIControlState.selected)
UITabBarItem.appearance().setTitleTextAttributes([NSAttributedString.Key.foregroundColor: selectedTint], for:UIControl.State.selected)
}
}

@IBInspectable var fontName: String = "" {
didSet {
UITabBarItem.appearance().setTitleTextAttributes([NSAttributedStringKey.foregroundColor: normalTint, NSAttributedStringKey.font: UIFont(name: fontName, size: 11)!], for: UIControlState())
UITabBarItem.appearance().setTitleTextAttributes([NSAttributedString.Key.foregroundColor: normalTint, NSAttributedString.Key.font: UIFont(name: fontName, size: 11)!], for: UIControl.State())
}
}

@IBInspectable var firstSelectedImage: UIImage? {
didSet {
if let image = firstSelectedImage {
var tabBarItems = self.tabBar.items as [UITabBarItem]!
tabBarItems?[0].selectedImage = image.withRenderingMode(UIImageRenderingMode.alwaysTemplate)
if let image = firstSelectedImage, var tabBarItems = self.tabBar.items {
tabBarItems[0].selectedImage = image.withRenderingMode(UIImage.RenderingMode.alwaysTemplate)
}
}
}

@IBInspectable var secondSelectedImage: UIImage? {
didSet {
if let image = secondSelectedImage {
var tabBarItems = self.tabBar.items as [UITabBarItem]!
tabBarItems?[1].selectedImage = image.withRenderingMode(UIImageRenderingMode.alwaysTemplate)
if let image = secondSelectedImage, var tabBarItems = self.tabBar.items {
tabBarItems[1].selectedImage = image.withRenderingMode(UIImage.RenderingMode.alwaysTemplate)
}
}
}

@IBInspectable var thirdSelectedImage: UIImage? {
didSet {
if let image = thirdSelectedImage {
var tabBarItems = self.tabBar.items as [UITabBarItem]!
tabBarItems?[2].selectedImage = image.withRenderingMode(UIImageRenderingMode.alwaysTemplate)
if let image = thirdSelectedImage, var tabBarItems = self.tabBar.items {
tabBarItems[2].selectedImage = image.withRenderingMode(UIImage.RenderingMode.alwaysTemplate)
}
}
}

@IBInspectable var fourthSelectedImage: UIImage? {
didSet {
if let image = fourthSelectedImage {
var tabBarItems = self.tabBar.items as [UITabBarItem]!
tabBarItems?[3].selectedImage = image.withRenderingMode(UIImageRenderingMode.alwaysTemplate)
if let image = fourthSelectedImage, var tabBarItems = self.tabBar.items {
tabBarItems[3].selectedImage = image.withRenderingMode(UIImage.RenderingMode.alwaysTemplate)
}
}
}

@IBInspectable var fifthSelectedImage: UIImage? {
didSet {
if let image = fifthSelectedImage {
var tabBarItems = self.tabBar.items as [UITabBarItem]!
tabBarItems?[4].selectedImage = image.withRenderingMode(UIImageRenderingMode.alwaysTemplate)
if let image = fifthSelectedImage, var tabBarItems = self.tabBar.items {
tabBarItems[4].selectedImage = image.withRenderingMode(UIImage.RenderingMode.alwaysTemplate)
}
}
}

override func viewDidLoad() {
super.viewDidLoad()

for item in self.tabBar.items as [UITabBarItem]! {
for item in self.tabBar.items ?? [] {
if let image = item.image {
item.image = image.imageWithColor(tintColor: self.normalTint).withRenderingMode(UIImageRenderingMode.alwaysOriginal)
item.image = image.imageWithColor(tintColor: self.normalTint).withRenderingMode(UIImage.RenderingMode.alwaysOriginal)
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions Spring/DesignableTextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import UIKit
@IBInspectable public var placeholderColor: UIColor = UIColor.clear {
didSet {
guard let placeholder = placeholder else { return }
attributedPlaceholder = NSAttributedString(string: placeholder, attributes: [NSAttributedStringKey.foregroundColor: placeholderColor])
attributedPlaceholder = NSAttributedString(string: placeholder, attributes: [NSAttributedString.Key.foregroundColor: placeholderColor])
layoutSubviews()

}
Expand All @@ -37,10 +37,10 @@ import UIKit
didSet {
let padding = UIView(frame: CGRect(x: 0, y: 0, width: sidePadding, height: sidePadding))

leftViewMode = UITextFieldViewMode.always
leftViewMode = UITextField.ViewMode.always
leftView = padding

rightViewMode = UITextFieldViewMode.always
rightViewMode = UITextField.ViewMode.always
rightView = padding
}
}
Expand All @@ -49,7 +49,7 @@ import UIKit
didSet {
let padding = UIView(frame: CGRect(x: 0, y: 0, width: leftPadding, height: 0))

leftViewMode = UITextFieldViewMode.always
leftViewMode = UITextField.ViewMode.always
leftView = padding
}
}
Expand All @@ -58,7 +58,7 @@ import UIKit
didSet {
let padding = UIView(frame: CGRect(x: 0, y: 0, width: rightPadding, height: 0))

rightViewMode = UITextFieldViewMode.always
rightViewMode = UITextField.ViewMode.always
rightView = padding
}
}
Expand Down Expand Up @@ -90,8 +90,8 @@ import UIKit
paragraphStyle.lineSpacing = lineHeight

let attributedString = NSMutableAttributedString(string: text)
attributedString.addAttribute(NSAttributedStringKey.paragraphStyle, value: paragraphStyle, range: NSRange(location: 0, length: attributedString.length))
attributedString.addAttribute(NSAttributedStringKey.font, value: font!, range: NSRange(location: 0, length: attributedString.length))
attributedString.addAttribute(NSAttributedString.Key.paragraphStyle, value: paragraphStyle, range: NSRange(location: 0, length: attributedString.length))
attributedString.addAttribute(NSAttributedString.Key.font, value: font!, range: NSRange(location: 0, length: attributedString.length))

self.attributedText = attributedString
}
Expand Down
4 changes: 2 additions & 2 deletions Spring/DesignableTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ import UIKit
paragraphStyle.lineSpacing = lineHeight

let attributedString = NSMutableAttributedString(string: text)
attributedString.addAttribute(NSAttributedStringKey.paragraphStyle, value: paragraphStyle, range: NSRange(location: 0, length: attributedString.length))
attributedString.addAttribute(NSAttributedStringKey.font, value: font!, range: NSRange(location: 0, length: attributedString.length))
attributedString.addAttribute(NSAttributedString.Key.paragraphStyle, value: paragraphStyle, range: NSRange(location: 0, length: attributedString.length))
attributedString.addAttribute(NSAttributedString.Key.font, value: font!, range: NSRange(location: 0, length: attributedString.length))

self.attributedText = attributedString
}
Expand Down
14 changes: 7 additions & 7 deletions Spring/KeyboardLayoutConstraint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public class KeyboardLayoutConstraint: NSLayoutConstraint {

offset = constant

NotificationCenter.default.addObserver(self, selector: #selector(KeyboardLayoutConstraint.keyboardWillShowNotification(_:)), name: NSNotification.Name.UIKeyboardWillShow, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(KeyboardLayoutConstraint.keyboardWillHideNotification(_:)), name: NSNotification.Name.UIKeyboardWillHide, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(KeyboardLayoutConstraint.keyboardWillShowNotification(_:)), name: UIResponder.keyboardWillShowNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(KeyboardLayoutConstraint.keyboardWillHideNotification(_:)), name: UIResponder.keyboardWillHideNotification, object: nil)
}

deinit {
Expand All @@ -47,16 +47,16 @@ public class KeyboardLayoutConstraint: NSLayoutConstraint {

@objc func keyboardWillShowNotification(_ notification: Notification) {
if let userInfo = notification.userInfo {
if let frameValue = userInfo[UIKeyboardFrameEndUserInfoKey] as? NSValue {
if let frameValue = userInfo[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue {
let frame = frameValue.cgRectValue
keyboardVisibleHeight = frame.size.height
}

self.updateConstant()
switch (userInfo[UIKeyboardAnimationDurationUserInfoKey] as? NSNumber, userInfo[UIKeyboardAnimationCurveUserInfoKey] as? NSNumber) {
switch (userInfo[UIResponder.keyboardAnimationDurationUserInfoKey] as? NSNumber, userInfo[UIResponder.keyboardAnimationCurveUserInfoKey] as? NSNumber) {
case let (.some(duration), .some(curve)):

let options = UIViewAnimationOptions(rawValue: curve.uintValue)
let options = UIView.AnimationOptions(rawValue: curve.uintValue)

UIView.animate(
withDuration: TimeInterval(duration.doubleValue),
Expand All @@ -82,10 +82,10 @@ public class KeyboardLayoutConstraint: NSLayoutConstraint {

if let userInfo = notification.userInfo {

switch (userInfo[UIKeyboardAnimationDurationUserInfoKey] as? NSNumber, userInfo[UIKeyboardAnimationCurveUserInfoKey] as? NSNumber) {
switch (userInfo[UIResponder.keyboardAnimationDurationUserInfoKey] as? NSNumber, userInfo[UIResponder.keyboardAnimationCurveUserInfoKey] as? NSNumber) {
case let (.some(duration), .some(curve)):

let options = UIViewAnimationOptions(rawValue: curve.uintValue)
let options = UIView.AnimationOptions(rawValue: curve.uintValue)

UIView.animate(
withDuration: TimeInterval(duration.doubleValue),
Expand Down
8 changes: 3 additions & 5 deletions Spring/Misc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import UIKit

public extension String {
public var length: Int { return self.characters.count }

public func toURL() -> NSURL? {
return NSURL(string: self)
}
Expand Down Expand Up @@ -73,7 +71,7 @@ public extension UIColor {
let scanner = Scanner(string: hex)
var hexValue: CUnsignedLongLong = 0
if scanner.scanHexInt64(&hexValue) {
switch (hex.characters.count) {
switch (hex.count) {
case 3:
red = CGFloat((hexValue & 0xF00) >> 8) / 15.0
green = CGFloat((hexValue & 0x0F0) >> 4) / 15.0
Expand Down Expand Up @@ -235,7 +233,7 @@ public func timeAgoSinceDate(date: Date, numericDates: Bool) -> String {
}

extension UIImageView {
func setImage(url: URL, contentMode mode: UIViewContentMode = .scaleAspectFit, placeholderImage: UIImage?) {
func setImage(url: URL, contentMode mode: UIView.ContentMode = .scaleAspectFit, placeholderImage: UIImage?) {
contentMode = mode
URLSession.shared.dataTask(with: url) { (data, response, error) in
guard
Expand All @@ -253,7 +251,7 @@ extension UIImageView {
}
}.resume()
}
func setImage(urlString: String, contentMode mode: UIViewContentMode = .scaleAspectFit, placeholderImage: UIImage?) {
func setImage(urlString: String, contentMode mode: UIView.ContentMode = .scaleAspectFit, placeholderImage: UIImage?) {
guard let url = URL(string: urlString) else {
image = placeholderImage
return
Expand Down
26 changes: 13 additions & 13 deletions Spring/Spring.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class Spring : NSObject {
}

func commonInit() {
NotificationCenter.default.addObserver(self, selector: #selector(Spring.didBecomeActiveNotification(_:)), name: NSNotification.Name.UIApplicationDidBecomeActive, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(Spring.didBecomeActiveNotification(_:)), name: UIApplication.didBecomeActiveNotification, object: nil)
}

@objc func didBecomeActiveNotification(_ notification: NSNotification) {
Expand All @@ -77,7 +77,7 @@ public class Spring : NSObject {
}

deinit {
NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIApplicationDidBecomeActive, object: nil)
NotificationCenter.default.removeObserver(self, name: UIApplication.didBecomeActiveNotification, object: nil)
}

private var autostart: Bool { set { self.view.autostart = newValue } get { return self.view.autostart }}
Expand Down Expand Up @@ -370,10 +370,10 @@ public class Spring : NSObject {
func getTimingFunction(curve: String) -> CAMediaTimingFunction {
if let curve = AnimationCurve(rawValue: curve) {
switch curve {
case .EaseIn: return CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseIn)
case .EaseOut: return CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut)
case .EaseInOut: return CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
case .Linear: return CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
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)
Expand Down Expand Up @@ -401,19 +401,19 @@ public class Spring : NSObject {
case .EaseInOutBack: return CAMediaTimingFunction(controlPoints: 0.68, -0.55, 0.265, 1.55)
}
}
return CAMediaTimingFunction(name: kCAMediaTimingFunctionDefault)
return CAMediaTimingFunction(name: CAMediaTimingFunctionName.default)
}

func getAnimationOptions(curve: String) -> UIViewAnimationOptions {
func getAnimationOptions(curve: String) -> UIView.AnimationOptions {
if let curve = AnimationCurve(rawValue: curve) {
switch curve {
case .EaseIn: return UIViewAnimationOptions.curveEaseIn
case .EaseOut: return UIViewAnimationOptions.curveEaseOut
case .EaseInOut: return UIViewAnimationOptions()
case .EaseIn: return UIView.AnimationOptions.curveEaseIn
case .EaseOut: return UIView.AnimationOptions.curveEaseOut
case .EaseInOut: return UIView.AnimationOptions()
default: break
}
}
return UIViewAnimationOptions.curveLinear
return UIView.AnimationOptions.curveLinear
}

public func animate() {
Expand Down Expand Up @@ -479,7 +479,7 @@ public class Spring : NSObject {
delay: TimeInterval(delay),
usingSpringWithDamping: damping,
initialSpringVelocity: velocity,
options: [getAnimationOptions(curve: curve), UIViewAnimationOptions.allowUserInteraction],
options: [getAnimationOptions(curve: curve), UIView.AnimationOptions.allowUserInteraction],
animations: { [weak self] in
if let _self = self
{
Expand Down
2 changes: 1 addition & 1 deletion Spring/SpringAnimation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ import UIKit
UIView.animate(
withDuration: duration,
delay: 0,
options: UIViewAnimationOptions(),
options: UIView.AnimationOptions(),
animations: {
animations()
}, completion: nil
Expand Down
Loading