diff --git a/EZSwiftExtensions.xcodeproj/project.pbxproj b/EZSwiftExtensions.xcodeproj/project.pbxproj index 5b4523be..a72d534b 100644 --- a/EZSwiftExtensions.xcodeproj/project.pbxproj +++ b/EZSwiftExtensions.xcodeproj/project.pbxproj @@ -853,6 +853,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, ); mainGroup = B5DC869F1C0ED06700972D0A; @@ -1350,7 +1351,7 @@ SDKROOT = macosx; SKIP_INSTALL = YES; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -1374,7 +1375,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; }; name = Release; }; @@ -1523,7 +1524,7 @@ PRODUCT_NAME = EZSwiftExtensions; SKIP_INSTALL = YES; SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -1544,7 +1545,7 @@ PRODUCT_NAME = EZSwiftExtensions; SKIP_INSTALL = YES; SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; @@ -1590,6 +1591,7 @@ PRODUCT_NAME = EZSwiftExtensions; SDKROOT = appletvos; SKIP_INSTALL = YES; + SWIFT_VERSION = 5.0; TVOS_DEPLOYMENT_TARGET = 9.0; }; name = Debug; @@ -1609,6 +1611,7 @@ PRODUCT_NAME = EZSwiftExtensions; SDKROOT = appletvos; SKIP_INSTALL = YES; + SWIFT_VERSION = 5.0; TVOS_DEPLOYMENT_TARGET = 9.0; }; name = Release; diff --git a/EZSwiftExtensions/UIStackViewExtensions.swift b/EZSwiftExtensions/UIStackViewExtensions.swift index 09554c03..b0ac197d 100644 --- a/EZSwiftExtensions/UIStackViewExtensions.swift +++ b/EZSwiftExtensions/UIStackViewExtensions.swift @@ -21,9 +21,9 @@ extension UIStackView { /// - alignment: the alignment of the stack view /// - axis: the axis (e.g. horizontal or vertical) /// - spacing: spacing between subviews, default is 0 - public convenience init(distribution: UIStackViewDistribution, - alignment: UIStackViewAlignment, - axis: UILayoutConstraintAxis, + public convenience init(distribution: UIStackView.Distribution, + alignment: UIStackView.Alignment, + axis: NSLayoutConstraint.Axis, spacing: CGFloat = 0) { self.init() self.distribution = distribution diff --git a/EZSwiftExtensionsExample.xcodeproj/project.pbxproj b/EZSwiftExtensionsExample.xcodeproj/project.pbxproj index e15b3b95..3128e2fa 100644 --- a/EZSwiftExtensionsExample.xcodeproj/project.pbxproj +++ b/EZSwiftExtensionsExample.xcodeproj/project.pbxproj @@ -251,6 +251,7 @@ TargetAttributes = { E1839DB41BF79335002212C6 = { CreatedOnToolsVersion = 7.0.1; + DevelopmentTeam = Y8MK4UJH8L; LastSwiftMigration = 0800; }; }; @@ -260,6 +261,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, Base, ); @@ -462,12 +464,13 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = Y8MK4UJH8L; INFOPLIST_FILE = EZSwiftExtensions/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.gbf.EZSwiftExtensions; PRODUCT_NAME = EZSwiftExtensionsExample; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -475,12 +478,13 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = Y8MK4UJH8L; INFOPLIST_FILE = EZSwiftExtensions/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.gbf.EZSwiftExtensions; PRODUCT_NAME = EZSwiftExtensionsExample; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; }; name = Release; }; diff --git a/Sources/ArrayExtensions.swift b/Sources/ArrayExtensions.swift index ade0127e..73a1cf30 100644 --- a/Sources/ArrayExtensions.swift +++ b/Sources/ArrayExtensions.swift @@ -23,7 +23,7 @@ extension Array { ///EZSE: Get a sub array from range of index public func get(at range: ClosedRange) -> Array { - let halfOpenClampedRange = Range(range).clamped(to: Range(indices)) + let halfOpenClampedRange = Range(range).clamped(to: indices) return Array(self[halfOpenClampedRange]) } diff --git a/Sources/BlockButton.swift b/Sources/BlockButton.swift index 587f5995..49e3b5b1 100755 --- a/Sources/BlockButton.swift +++ b/Sources/BlockButton.swift @@ -60,16 +60,16 @@ open class BlockButton: UIButton { } private func defaultInit() { - addTarget(self, action: #selector(BlockButton.didPressed(_:)), for: UIControlEvents.touchUpInside) - addTarget(self, action: #selector(BlockButton.highlight), for: [UIControlEvents.touchDown, UIControlEvents.touchDragEnter]) + addTarget(self, action: #selector(BlockButton.didPressed(_:)), for: UIControl.Event.touchUpInside) + addTarget(self, action: #selector(BlockButton.highlight), for: [UIControl.Event.touchDown, UIControl.Event.touchDragEnter]) addTarget(self, action: #selector(BlockButton.unhighlight), for: [ - UIControlEvents.touchUpInside, - UIControlEvents.touchUpOutside, - UIControlEvents.touchCancel, - UIControlEvents.touchDragExit + UIControl.Event.touchUpInside, + UIControl.Event.touchUpOutside, + UIControl.Event.touchCancel, + UIControl.Event.touchDragExit ]) - setTitleColor(UIColor.black, for: UIControlState.normal) - setTitleColor(UIColor.blue, for: UIControlState.selected) + setTitleColor(UIColor.black, for: UIControl.State.normal) + setTitleColor(UIColor.blue, for: UIControl.State.selected) } open func addAction(_ action: @escaping BlockButtonAction) { diff --git a/Sources/BlockLongPress.swift b/Sources/BlockLongPress.swift index 52d64b94..9e5f5790 100755 --- a/Sources/BlockLongPress.swift +++ b/Sources/BlockLongPress.swift @@ -25,7 +25,7 @@ open class BlockLongPress: UILongPressGestureRecognizer { } @objc open func didLongPressed(_ longPress: UILongPressGestureRecognizer) { - if longPress.state == UIGestureRecognizerState.began { + if longPress.state == UIGestureRecognizer.State.began { longPressAction?(longPress) } } diff --git a/Sources/BlockSwipe.swift b/Sources/BlockSwipe.swift index 265a2c55..57c80591 100755 --- a/Sources/BlockSwipe.swift +++ b/Sources/BlockSwipe.swift @@ -19,7 +19,7 @@ open class BlockSwipe: UISwipeGestureRecognizer { } public convenience init ( - direction: UISwipeGestureRecognizerDirection, + direction: UISwipeGestureRecognizer.Direction, fingerCount: Int = 1, action: ((UISwipeGestureRecognizer) -> Void)?) { self.init() diff --git a/Sources/BlockWebView.swift b/Sources/BlockWebView.swift index ea3e8683..5fa5001b 100755 --- a/Sources/BlockWebView.swift +++ b/Sources/BlockWebView.swift @@ -39,7 +39,7 @@ open class BlockWebView: UIWebView, UIWebViewDelegate { didFailLoad? (webView.request!, error) } - open func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool { + open func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebView.NavigationType) -> Bool { if let should = shouldStartLoadingRequest { return should (request) } else { diff --git a/Sources/DateExtensions.swift b/Sources/DateExtensions.swift index 01e2df3c..c570115a 100644 --- a/Sources/DateExtensions.swift +++ b/Sources/DateExtensions.swift @@ -137,29 +137,29 @@ extension Date { } /// EZSE: Easy creation of time passed String. Can be Years, Months, days, hours, minutes or seconds. Useful for localization - public func timePassed() -> TimePassed { - - let date = Date() - let calendar = Calendar.autoupdatingCurrent - let components = (calendar as NSCalendar).components([.year, .month, .day, .hour, .minute, .second], from: self, to: date, options: []) - - if components.year! >= 1 { - return TimePassed.year(components.year!) - } else if components.month! >= 1 { - return TimePassed.month(components.month!) - } else if components.day! >= 1 { - return TimePassed.day(components.day!) - } else if components.hour! >= 1 { - return TimePassed.hour(components.hour!) - } else if components.minute! >= 1 { - return TimePassed.minute(components.minute!) - } else if components.second! >= 1 { - return TimePassed.second(components.second!) - } else { - return TimePassed.now - } - } - +// public func timePassed() -> TimePassed { +// +// let date = Date() +// let calendar = Calendar.autoupdatingCurrent +// let components = (calendar as NSCalendar).components([.year, .month, .day, .hour, .minute, .second], from: self, to: date, options: []) +// +// if components.year! >= 1 { +// return TimePassed.year(components.year!) +// } else if components.month! >= 1 { +// return TimePassed.month(components.month!) +// } else if components.day! >= 1 { +// return TimePassed.day(components.day!) +// } else if components.hour! >= 1 { +// return TimePassed.hour(components.hour!) +// } else if components.minute! >= 1 { +// return TimePassed.minute(components.minute!) +// } else if components.second! >= 1 { +// return TimePassed.second(components.second!) +// } else { +// return TimePassed.now +// } +// } + /// EZSE: Check if date is in future. public var isFuture: Bool { return self > Date() diff --git a/Sources/EZSwiftFunctions.swift b/Sources/EZSwiftFunctions.swift index 4325923c..28be35a9 100644 --- a/Sources/EZSwiftFunctions.swift +++ b/Sources/EZSwiftFunctions.swift @@ -141,7 +141,7 @@ public struct ez { #if os(iOS) - if UIInterfaceOrientationIsPortrait(screenOrientation) { + if screenOrientation == .portrait || screenOrientation == .portraitUpsideDown { return UIScreen.main.bounds.size.width } else { return UIScreen.main.bounds.size.height @@ -159,7 +159,7 @@ public struct ez { #if os(iOS) - if UIInterfaceOrientationIsPortrait(screenOrientation) { + if screenOrientation == .portrait || screenOrientation == .portraitUpsideDown { return UIScreen.main.bounds.size.height } else { return UIScreen.main.bounds.size.width @@ -183,7 +183,7 @@ public struct ez { /// EZSE: Return screen's height without StatusBar public static var screenHeightWithoutStatusBar: CGFloat { - if UIInterfaceOrientationIsPortrait(screenOrientation) { + if screenOrientation == .portrait || screenOrientation == .portraitUpsideDown { return UIScreen.main.bounds.size.height - screenStatusBarHeight } else { return UIScreen.main.bounds.size.width - screenStatusBarHeight @@ -202,7 +202,7 @@ public struct ez { /// EZSE: Calls action when a screen shot is taken public static func detectScreenShot(_ action: @escaping () -> Void) { let mainQueue = OperationQueue.main - _ = NotificationCenter.default.addObserver(forName: NSNotification.Name.UIApplicationUserDidTakeScreenshot, object: nil, queue: mainQueue) { _ in + _ = NotificationCenter.default.addObserver(forName: UIApplication.userDidTakeScreenshotNotification, object: nil, queue: mainQueue) { _ in // executes after screenshot action() } diff --git a/Sources/IntExtensions.swift b/Sources/IntExtensions.swift index b7cf2ffd..a0784f3b 100644 --- a/Sources/IntExtensions.swift +++ b/Sources/IntExtensions.swift @@ -7,6 +7,7 @@ // import Foundation +import AVFoundation extension Int { /// EZSE: Checks if the integer is even. diff --git a/Sources/NSAttributedStringExtensions.swift b/Sources/NSAttributedStringExtensions.swift index 14b2ea11..7f09bfdc 100644 --- a/Sources/NSAttributedStringExtensions.swift +++ b/Sources/NSAttributedStringExtensions.swift @@ -6,6 +6,8 @@ // Copyright (c) 2016 Lucas Farah. All rights reserved. // +import Foundation + #if os(iOS) || os(tvOS) extension NSAttributedString { @@ -17,7 +19,7 @@ extension NSAttributedString { guard let copy = self.mutableCopy() as? NSMutableAttributedString else { return self } let range = (self.string as NSString).range(of: self.string) - copy.addAttributes([NSAttributedStringKey.font: UIFont.boldSystemFont(ofSize: UIFont.systemFontSize)], range: range) + copy.addAttributes([NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: UIFont.systemFontSize)], range: range) return copy } @@ -28,7 +30,7 @@ extension NSAttributedString { guard let copy = self.mutableCopy() as? NSMutableAttributedString else { return self } let range = (self.string as NSString).range(of: self.string) - copy.addAttributes([NSAttributedStringKey.underlineStyle: NSUnderlineStyle.styleSingle.rawValue], range: range) + copy.addAttributes([NSAttributedString.Key.underlineStyle: NSUnderlineStyle.single.rawValue], range: range) return copy } @@ -39,7 +41,7 @@ extension NSAttributedString { guard let copy = self.mutableCopy() as? NSMutableAttributedString else { return self } let range = (self.string as NSString).range(of: self.string) - copy.addAttributes([NSAttributedStringKey.font: UIFont.italicSystemFont(ofSize: UIFont.systemFontSize)], range: range) + copy.addAttributes([NSAttributedString.Key.font: UIFont.italicSystemFont(ofSize: UIFont.systemFontSize)], range: range) return copy } @@ -49,7 +51,7 @@ extension NSAttributedString { let range = (self.string as NSString).range(of: self.string) let attributes = [ - NSAttributedStringKey.strikethroughStyle: NSNumber(value: NSUnderlineStyle.styleSingle.rawValue as Int)] + NSAttributedString.Key.strikethroughStyle: NSNumber(value: NSUnderlineStyle.single.rawValue as Int)] copy.addAttributes(attributes, range: range) return copy @@ -62,7 +64,7 @@ extension NSAttributedString { guard let copy = self.mutableCopy() as? NSMutableAttributedString else { return self } let range = (self.string as NSString).range(of: self.string) - copy.addAttributes([NSAttributedStringKey.foregroundColor: color], range: range) + copy.addAttributes([NSAttributedString.Key.foregroundColor: color], range: range) return copy } } diff --git a/Sources/NSObjectExtensions.swift b/Sources/NSObjectExtensions.swift index 7878a317..f711deb6 100644 --- a/Sources/NSObjectExtensions.swift +++ b/Sources/NSObjectExtensions.swift @@ -6,6 +6,8 @@ // Copyright (c) 2015 Goktug Yilmaz. All rights reserved. // +import Foundation + #if os(iOS) || os(tvOS) extension NSObject { diff --git a/Sources/StringExtensions.swift b/Sources/StringExtensions.swift index 2bb103a2..47779a9d 100644 --- a/Sources/StringExtensions.swift +++ b/Sources/StringExtensions.swift @@ -370,7 +370,7 @@ extension String { ///EZSE: Returns bold NSAttributedString public func bold() -> NSAttributedString { - let boldString = NSMutableAttributedString(string: self, attributes: [NSAttributedStringKey.font: UIFont.boldSystemFont(ofSize: UIFont.systemFontSize)]) + let boldString = NSMutableAttributedString(string: self, attributes: [NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: UIFont.systemFontSize)]) return boldString } @@ -380,7 +380,7 @@ extension String { ///EZSE: Returns underlined NSAttributedString public func underline() -> NSAttributedString { - let underlineString = NSAttributedString(string: self, attributes: [NSAttributedStringKey.underlineStyle: NSUnderlineStyle.styleSingle.rawValue]) + let underlineString = NSAttributedString(string: self, attributes: [NSAttributedString.Key.underlineStyle: NSUnderlineStyle.single.rawValue]) return underlineString } @@ -390,7 +390,7 @@ extension String { ///EZSE: Returns italic NSAttributedString public func italic() -> NSAttributedString { - let italicString = NSMutableAttributedString(string: self, attributes: [NSAttributedStringKey.font: UIFont.italicSystemFont(ofSize: UIFont.systemFontSize)]) + let italicString = NSMutableAttributedString(string: self, attributes: [NSAttributedString.Key.font: UIFont.italicSystemFont(ofSize: UIFont.systemFontSize)]) return italicString } @@ -400,11 +400,11 @@ extension String { ///EZSE: Returns hight of rendered string public func height(_ width: CGFloat, font: UIFont, lineBreakMode: NSLineBreakMode?) -> CGFloat { - var attrib: [NSAttributedStringKey: Any] = [NSAttributedStringKey.font: font] + var attrib: [NSAttributedString.Key: Any] = [NSAttributedString.Key.font: font] if lineBreakMode != nil { let paragraphStyle = NSMutableParagraphStyle() paragraphStyle.lineBreakMode = lineBreakMode! - attrib.updateValue(paragraphStyle, forKey: NSAttributedStringKey.paragraphStyle) + attrib.updateValue(paragraphStyle, forKey: NSAttributedString.Key.paragraphStyle) } let size = CGSize(width: width, height: CGFloat(Double.greatestFiniteMagnitude)) return ceil((self as NSString).boundingRect(with: size, options: NSStringDrawingOptions.usesLineFragmentOrigin, attributes: attrib, context: nil).height) @@ -416,7 +416,7 @@ extension String { ///EZSE: Returns NSAttributedString public func color(_ color: UIColor) -> NSAttributedString { - let colorString = NSMutableAttributedString(string: self, attributes: [NSAttributedStringKey.foregroundColor: color]) + let colorString = NSMutableAttributedString(string: self, attributes: [NSAttributedString.Key.foregroundColor: color]) return colorString } @@ -435,7 +435,7 @@ extension String { } let attrText = NSMutableAttributedString(string: self) for range in ranges { - attrText.addAttribute(NSAttributedStringKey.foregroundColor, value: color, range: range) + attrText.addAttribute(NSAttributedString.Key.foregroundColor, value: color, range: range) } return attrText } diff --git a/Sources/UIButtonExtensions.swift b/Sources/UIButtonExtensions.swift index 1e500a4a..94dde5d2 100644 --- a/Sources/UIButtonExtensions.swift +++ b/Sources/UIButtonExtensions.swift @@ -15,11 +15,11 @@ extension UIButton { public convenience init(x: CGFloat, y: CGFloat, w: CGFloat, h: CGFloat, target: AnyObject, action: Selector) { self.init(frame: CGRect(x: x, y: y, width: w, height: h)) - addTarget(target, action: action, for: UIControlEvents.touchUpInside) + addTarget(target, action: action, for: UIControl.Event.touchUpInside) } /// EZSwiftExtensions: Set a background color for the button. - public func setBackgroundColor(_ color: UIColor, forState: UIControlState) { + public func setBackgroundColor(_ color: UIColor, forState: UIControl.State) { UIGraphicsBeginImageContext(CGSize(width: 1, height: 1)) UIGraphicsGetCurrentContext()?.setFillColor(color.cgColor) UIGraphicsGetCurrentContext()?.fill(CGRect(x: 0, y: 0, width: 1, height: 1)) diff --git a/Sources/UIImageExtensions.swift b/Sources/UIImageExtensions.swift index c53678f0..93d3f469 100644 --- a/Sources/UIImageExtensions.swift +++ b/Sources/UIImageExtensions.swift @@ -14,17 +14,18 @@ extension UIImage { /// EZSE: Returns base64 string public var base64: String { - return UIImageJPEGRepresentation(self, 1.0)!.base64EncodedString() + // return UIImageJPEGRepresentation(self, 1.0)!.base64EncodedString() + return self.jpegData(compressionQuality: 1.0)!.base64EncodedString() } /// EZSE: Returns compressed image to rate from 0 to 1 public func compressImage(rate: CGFloat) -> Data? { - return UIImageJPEGRepresentation(self, rate) + return self.jpegData(compressionQuality: 1.0) } /// EZSE: Returns Image size in Bytes public func getSizeAsBytes() -> Int { - return UIImageJPEGRepresentation(self, 1)?.count ?? 0 + return self.jpegData(compressionQuality: 1.0)?.count ?? 0 } /// EZSE: Returns Image size in Kylobites @@ -89,7 +90,7 @@ extension UIImage { } let scaledBounds: CGRect = CGRect(x: bound.x * self.scale, y: bound.y * self.scale, width: bound.w * self.scale, height: bound.h * self.scale) let imageRef = self.cgImage?.cropping(to: scaledBounds) - let croppedImage: UIImage = UIImage(cgImage: imageRef!, scale: self.scale, orientation: UIImageOrientation.up) + let croppedImage: UIImage = UIImage(cgImage: imageRef!, scale: self.scale, orientation: UIImage.Orientation.up) return croppedImage } diff --git a/Sources/UITextFieldExtensions.swift b/Sources/UITextFieldExtensions.swift index 3943a456..4e3f30cb 100644 --- a/Sources/UITextFieldExtensions.swift +++ b/Sources/UITextFieldExtensions.swift @@ -31,7 +31,7 @@ extension UITextField { let leftView = UIView() leftView.frame = CGRect(x: 0, y: 0, width: blankSize, height: frame.height) self.leftView = leftView - self.leftViewMode = UITextFieldViewMode.always + self.leftViewMode = UITextField.ViewMode.always } /// EZSE: Add a image icon on the left side of the textfield @@ -43,7 +43,7 @@ extension UITextField { imgView.image = image leftView.addSubview(imgView) self.leftView = leftView - self.leftViewMode = UITextFieldViewMode.always + self.leftViewMode = UITextField.ViewMode.always } /// EZSE: Ways to validate by comparison diff --git a/Sources/UIViewControllerExtensions.swift b/Sources/UIViewControllerExtensions.swift index 6334287e..600045e1 100644 --- a/Sources/UIViewControllerExtensions.swift +++ b/Sources/UIViewControllerExtensions.swift @@ -33,52 +33,52 @@ extension UIViewController { /// /// ⚠️ You also need to implement ```keyboardWillShowNotification(_ notification: Notification)``` open func addKeyboardWillShowNotification() { - self.addNotificationObserver(NSNotification.Name.UIKeyboardWillShow.rawValue, selector: #selector(UIViewController.keyboardWillShowNotification(_:))) + self.addNotificationObserver(UIResponder.keyboardWillShowNotification.rawValue, selector: #selector(UIViewController.keyboardWillShowNotification(_:))) } ///EZSE: Adds a NotificationCenter Observer for keyboardDidShowNotification() /// /// ⚠️ You also need to implement ```keyboardDidShowNotification(_ notification: Notification)``` public func addKeyboardDidShowNotification() { - self.addNotificationObserver(NSNotification.Name.UIKeyboardDidShow.rawValue, selector: #selector(UIViewController.keyboardDidShowNotification(_:))) + self.addNotificationObserver(UIResponder.keyboardDidShowNotification.rawValue, selector: #selector(UIViewController.keyboardDidShowNotification(_:))) } ///EZSE: Adds a NotificationCenter Observer for keyboardWillHideNotification() /// /// ⚠️ You also need to implement ```keyboardWillHideNotification(_ notification: Notification)``` open func addKeyboardWillHideNotification() { - self.addNotificationObserver(NSNotification.Name.UIKeyboardWillHide.rawValue, selector: #selector(UIViewController.keyboardWillHideNotification(_:))) + self.addNotificationObserver(UIResponder.keyboardWillHideNotification.rawValue, selector: #selector(UIViewController.keyboardWillHideNotification(_:))) } ///EZSE: Adds a NotificationCenter Observer for keyboardDidHideNotification() /// /// ⚠️ You also need to implement ```keyboardDidHideNotification(_ notification: Notification)``` open func addKeyboardDidHideNotification() { - self.addNotificationObserver(NSNotification.Name.UIKeyboardDidHide.rawValue, selector: #selector(UIViewController.keyboardDidHideNotification(_:))) + self.addNotificationObserver(UIResponder.keyboardDidHideNotification.rawValue, selector: #selector(UIViewController.keyboardDidHideNotification(_:))) } ///EZSE: Removes keyboardWillShowNotification()'s NotificationCenter Observer open func removeKeyboardWillShowNotification() { - self.removeNotificationObserver(NSNotification.Name.UIKeyboardWillShow.rawValue) + self.removeNotificationObserver(UIResponder.keyboardWillShowNotification.rawValue) } ///EZSE: Removes keyboardDidShowNotification()'s NotificationCenter Observer open func removeKeyboardDidShowNotification() { - self.removeNotificationObserver(NSNotification.Name.UIKeyboardDidShow.rawValue) + self.removeNotificationObserver(UIResponder.keyboardDidShowNotification.rawValue) } ///EZSE: Removes keyboardWillHideNotification()'s NotificationCenter Observer open func removeKeyboardWillHideNotification() { - self.removeNotificationObserver(NSNotification.Name.UIKeyboardWillHide.rawValue) + self.removeNotificationObserver(UIResponder.keyboardWillHideNotification.rawValue) } ///EZSE: Removes keyboardDidHideNotification()'s NotificationCenter Observer open func removeKeyboardDidHideNotification() { - self.removeNotificationObserver(NSNotification.Name.UIKeyboardDidHide.rawValue) + self.removeNotificationObserver(UIResponder.keyboardDidHideNotification.rawValue) } @objc open func keyboardDidShowNotification(_ notification: Notification) { - if let nInfo = (notification as NSNotification).userInfo, let value = nInfo[UIKeyboardFrameEndUserInfoKey] as? NSValue { + if let nInfo = (notification as NSNotification).userInfo, let value = nInfo[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue { let frame = value.cgRectValue keyboardDidShowWithFrame(frame) @@ -86,7 +86,7 @@ extension UIViewController { } @objc open func keyboardWillShowNotification(_ notification: Notification) { - if let nInfo = (notification as NSNotification).userInfo, let value = nInfo[UIKeyboardFrameEndUserInfoKey] as? NSValue { + if let nInfo = (notification as NSNotification).userInfo, let value = nInfo[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue { let frame = value.cgRectValue keyboardWillShowWithFrame(frame) @@ -94,7 +94,7 @@ extension UIViewController { } @objc open func keyboardWillHideNotification(_ notification: Notification) { - if let nInfo = (notification as NSNotification).userInfo, let value = nInfo[UIKeyboardFrameEndUserInfoKey] as? NSValue { + if let nInfo = (notification as NSNotification).userInfo, let value = nInfo[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue { let frame = value.cgRectValue keyboardWillHideWithFrame(frame) @@ -102,7 +102,7 @@ extension UIViewController { } @objc open func keyboardDidHideNotification(_ notification: Notification) { - if let nInfo = (notification as NSNotification).userInfo, let value = nInfo[UIKeyboardFrameEndUserInfoKey] as? NSValue { + if let nInfo = (notification as NSNotification).userInfo, let value = nInfo[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue { let frame = value.cgRectValue keyboardDidHideWithFrame(frame) @@ -256,9 +256,9 @@ extension UIViewController { ///EZSE: Adds the specified view controller as a child of the current view controller. open func addAsChildViewController(_ vc: UIViewController, toView: UIView) { - self.addChildViewController(vc) + self.addChild(vc) toView.addSubview(vc.view) - vc.didMove(toParentViewController: self) + vc.didMove(toParent: self) } ///EZSE: Adds image named: as a UIImageView in the Background @@ -267,7 +267,7 @@ extension UIViewController { let imageView = UIImageView(frame: view.frame) imageView.image = image view.addSubview(imageView) - view.sendSubview(toBack: imageView) + view.sendSubviewToBack(imageView) } ///EZSE: Adds UIImage as a UIImageView in the Background @@ -275,7 +275,7 @@ extension UIViewController { let imageView = UIImageView(frame: view.frame) imageView.image = image view.addSubview(imageView) - view.sendSubview(toBack: imageView) + view.sendSubviewToBack(imageView) } #if os(iOS) diff --git a/Sources/UIViewExtensions.swift b/Sources/UIViewExtensions.swift index 6b8fc807..2a20e0a6 100644 --- a/Sources/UIViewExtensions.swift +++ b/Sources/UIViewExtensions.swift @@ -412,7 +412,7 @@ extension UIView { delay: 0, usingSpringWithDamping: UIViewAnimationSpringDamping, initialSpringVelocity: UIViewAnimationSpringVelocity, - options: UIViewAnimationOptions.allowAnimatedContent, + options: UIView.AnimationOptions.allowAnimatedContent, animations: animations, completion: completion ) @@ -485,7 +485,7 @@ extension UIView { } /// EZSwiftExtensions - public func addSwipeGesture(direction: UISwipeGestureRecognizerDirection, numberOfTouches: Int = 1, target: AnyObject, action: Selector) { + public func addSwipeGesture(direction: UISwipeGestureRecognizer.Direction, numberOfTouches: Int = 1, target: AnyObject, action: Selector) { let swipe = UISwipeGestureRecognizer(target: target, action: action) swipe.direction = direction @@ -500,7 +500,7 @@ extension UIView { } /// EZSwiftExtensions - Make sure you use "[weak self] (gesture) in" if you are using the keyword self inside the closure or there might be a memory leak - public func addSwipeGesture(direction: UISwipeGestureRecognizerDirection, numberOfTouches: Int = 1, action: ((UISwipeGestureRecognizer) -> Void)?) { + public func addSwipeGesture(direction: UISwipeGestureRecognizer.Direction, numberOfTouches: Int = 1, action: ((UISwipeGestureRecognizer) -> Void)?) { let swipe = BlockSwipe(direction: direction, fingerCount: numberOfTouches, action: action) addGestureRecognizer(swipe) isUserInteractionEnabled = true