diff --git a/EZSwiftExtensions.xcodeproj/project.pbxproj b/EZSwiftExtensions.xcodeproj/project.pbxproj index 5b4523be..9d2c65a4 100644 --- a/EZSwiftExtensions.xcodeproj/project.pbxproj +++ b/EZSwiftExtensions.xcodeproj/project.pbxproj @@ -853,6 +853,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, ); mainGroup = B5DC869F1C0ED06700972D0A; @@ -1523,7 +1524,7 @@ PRODUCT_NAME = EZSwiftExtensions; SKIP_INSTALL = YES; SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; 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 = 4.2; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; diff --git a/EZSwiftExtensions.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/EZSwiftExtensions.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 00000000..18d98100 --- /dev/null +++ b/EZSwiftExtensions.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + 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/Sources/ArrayExtensions.swift b/Sources/ArrayExtensions.swift index ade0127e..b87b28d6 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]) } @@ -114,7 +114,7 @@ extension Array where Element: Equatable { /// EZSE: Returns the indexes of the object public func indexes(of element: Element) -> [Int] { - return enumerated().flatMap { ($0.element == element) ? $0.offset : nil } + return enumerated().compactMap { ($0.element == element) ? $0.offset : nil } } /// EZSE: Returns the last index of the object @@ -230,19 +230,19 @@ extension Collection { extension Array { /// EZSE: Checks if array contains at least 1 instance of the given object type - @available(*, deprecated: 1.8, renamed: "containsType(of:)") + @available(*, deprecated, renamed: "containsType(of:)") public func containsInstanceOf(_ element: T) -> Bool { return containsType(of: element) } /// EZSE: Gets the object at the specified index, if it exists. - @available(*, deprecated: 1.8, renamed: "get(at:)") +// @available(*, deprecated, renamed: "t:)") public func get(_ index: Int) -> Element? { return get(at: index) } /// EZSE: Checks if all elements in the array are true of false - @available(*, deprecated: 1.8, renamed: "testAll(is:)") +// @available(*, deprecated, renamed: "testA:)") public func testIfAllIs(_ condition: Bool) -> Bool { return testAll(is: condition) } @@ -252,7 +252,7 @@ extension Array { extension Array where Element: Equatable { /// EZSE: Removes the first given object - @available(*, deprecated: 1.8, renamed: "removeFirst(_:)") + @available(*, deprecated, renamed: "removeFirst(_:)") public mutating func removeFirstObject(_ object: Element) { removeFirst(object) } @@ -263,7 +263,7 @@ extension Array where Element: Equatable { extension Array { /// EZSE: Prepends an object to the array. - @available(*, deprecated: 1.7, renamed: "insertFirst(_:)") + @available(*, deprecated, renamed: "insertFirst(_:)") public mutating func insertAsFirst(_ newElement: Element) { insertFirst(newElement) } @@ -273,27 +273,27 @@ extension Array { extension Array where Element: Equatable { /// EZSE: Checks if the main array contains the parameter array - @available(*, deprecated: 1.7, renamed: "contains(_:)") + @available(*, deprecated, renamed: "contains(_:)") public func containsArray(_ array: [Element]) -> Bool { return contains(array) } /// EZSE: Returns the indexes of the object - @available(*, deprecated: 1.7, renamed: "indexes(of:)") + @available(*, deprecated, renamed: "indexes(of:)") public func indexesOf(_ object: Element) -> [Int] { return indexes(of: object) } /// EZSE: Returns the last index of the object - @available(*, deprecated: 1.7, renamed: "lastIndex(_:)") + @available(*, deprecated, renamed: "lastIndex(_:)") public func lastIndexOf(_ object: Element) -> Int? { return lastIndex(of: object) } /// EZSE: Removes the first given object - @available(*, deprecated: 1.7, renamed: "removeFirstObject(_:)") + @available(*, deprecated, renamed: "removeFirstObject(_:)") public mutating func removeObject(_ object: Element) { - removeFirstObject(object) + removeFirst(object) } } @@ -304,13 +304,13 @@ extension Array { /// EZSE: Creates an array with values generated by running each value of self /// through the mapFunction and discarding nil return values. - @available(*, deprecated: 1.6, renamed: "flatMap(_:)") + @available(*, deprecated, renamed: "flatMap(_:)") public func mapFilter(mapFunction map: (Element) -> (V)?) -> [V] { - return flatMap { map($0) } + return compactMap { map($0) } } /// EZSE: Iterates on each element of the array with its index. (Index, Element) - @available(*, deprecated: 1.6, renamed: "forEachEnumerated(_:)") + @available(*, deprecated, renamed: "forEachEnumerated(_:)") public func each(_ call: @escaping (Int, Element) -> Void) { forEachEnumerated(call) } 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/BundleExtensions.swift b/Sources/BundleExtensions.swift index 057ec693..e5b867ef 100644 --- a/Sources/BundleExtensions.swift +++ b/Sources/BundleExtensions.swift @@ -15,13 +15,13 @@ public extension Bundle { // Usage: Set some UIView subclass as xib's owner class // Bundle.loadNib("ViewXibName", owner: self) //some UIView subclass // self.addSubview(self.contentView) - public class func loadNib(_ name: String, owner: AnyObject!) { + class func loadNib(_ name: String, owner: AnyObject!) { _ = Bundle.main.loadNibNamed(name, owner: owner, options: nil)?[0] } /// EZSE: load xib /// Usage: let view: ViewXibName = Bundle.loadNib("ViewXibName") - public class func loadNib(_ name: String) -> T? { + class func loadNib(_ name: String) -> T? { return Bundle.main.loadNibNamed(name, owner: nil, options: nil)?[0] as? T } diff --git a/Sources/CGFloatExtensions.swift b/Sources/CGFloatExtensions.swift index 163b8ab1..289473e6 100644 --- a/Sources/CGFloatExtensions.swift +++ b/Sources/CGFloatExtensions.swift @@ -15,7 +15,7 @@ extension CGFloat { /// EZSE: Return the central value of CGFloat. public var center: CGFloat { return (self / 2) } - @available(*, deprecated: 1.8, renamed: "degreesToRadians") + @available(*, deprecated, renamed: "degreesToRadians") public func toRadians() -> CGFloat { return (.pi * self) / 180.0 } @@ -52,7 +52,7 @@ extension CGFloat { /// EZSE: Returns a random floating point number between 0.0 and 1.0, inclusive. public static func random() -> CGFloat { - return CGFloat(Float(arc4random()) / 0xFFFFFFFF) + return CGFloat(Float(arc4random()) / Float(0xFFFFFFFF)) } /// EZSE: Returns a random floating point number in the range min...max, inclusive. diff --git a/Sources/DoubleExtensions.swift b/Sources/DoubleExtensions.swift index d3f53f17..1d1d26e4 100644 --- a/Sources/DoubleExtensions.swift +++ b/Sources/DoubleExtensions.swift @@ -37,25 +37,25 @@ extension Double { extension Double { /// EZSE: Returns a Double rounded to decimal - @available(*, deprecated: 1.8, renamed: "rounded(toPlaces:)") + @available(*, deprecated, renamed: "rounded(toPlaces:)") public func getRoundedByPlaces(_ places: Int) -> Double { return rounded(toPlaces: places) } /// EZSE: Rounds the current Double rounded to decimal - @available(*, deprecated: 1.8, renamed: "round(toPlaces:)") + @available(*, deprecated, renamed: "round(toPlaces:)") public mutating func roundByPlaces(_ places: Int) { self.round(toPlaces: places) } /// EZSE: Returns a Double Ceil to decimal - @available(*, deprecated: 1.8, renamed: "ceiled(toPlaces:)") + @available(*, deprecated, renamed: "ceiled(toPlaces:)") public func getCeiledByPlaces(_ places: Int) -> Double { return ceiled(toPlaces: places) } /// EZSE: Ceils current Double to number of places - @available(*, deprecated: 1.8, renamed: "ceil(toPlaces:)") + @available(*, deprecated, renamed: "ceil(toPlaces:)") public mutating func ceilByPlaces(_ places: Int) { self.ceil(toPlaces: places) } diff --git a/Sources/EZSwiftFunctions.swift b/Sources/EZSwiftFunctions.swift index 4325923c..1be673fa 100644 --- a/Sources/EZSwiftFunctions.swift +++ b/Sources/EZSwiftFunctions.swift @@ -78,7 +78,7 @@ public struct ez { /// EZSE: Returns true if its simulator and not a device //TODO: Add to readme public static var isSimulator: Bool { - #if (arch(i386) || arch(x86_64)) && os(iOS) + #if targetEnvironment(simulator) return true #else return false @@ -87,7 +87,7 @@ public struct ez { /// EZSE: Returns true if its on a device and not a simulator //TODO: Add to readme public static var isDevice: Bool { - #if (arch(i386) || arch(x86_64)) && os(iOS) + #if targetEnvironment(simulator) return false #else return true @@ -141,7 +141,7 @@ public struct ez { #if os(iOS) - if UIInterfaceOrientationIsPortrait(screenOrientation) { + if screenOrientation.isPortrait { 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.isPortrait { 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.isPortrait { 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() } @@ -265,38 +265,38 @@ public struct ez { } /// EZSE: Gobal main queue - @available(*, deprecated: 1.7, renamed: "DispatchQueue.main") + @available(*, deprecated, renamed: "DispatchQueue.main") public var globalMainQueue: DispatchQueue { return DispatchQueue.main } /// EZSE: Gobal queue with user interactive priority - @available(*, deprecated: 1.7, renamed: "DispatchQueue.main") + @available(*, deprecated, renamed: "DispatchQueue.main") public var globalUserInteractiveQueue: DispatchQueue { return DispatchQueue.global(qos: .userInteractive) } /// EZSE: Gobal queue with user initiated priority - @available(*, deprecated: 1.7, renamed: "DispatchQueue.global()") + @available(*, deprecated, renamed: "DispatchQueue.global()") public var globalUserInitiatedQueue: DispatchQueue { return DispatchQueue.global(qos: .userInitiated) } /// EZSE: Gobal queue with utility priority - @available(*, deprecated: 1.7, renamed: "DispatchQueue.global()") + @available(*, deprecated, renamed: "DispatchQueue.global()") public var globalUtilityQueue: DispatchQueue { return DispatchQueue.global(qos: .utility) } /// EZSE: Gobal queue with background priority - @available(*, deprecated: 1.7, renamed: "DispatchQueue.global()") + @available(*, deprecated, renamed: "DispatchQueue.global()") public var globalBackgroundQueue: DispatchQueue { return DispatchQueue.global(qos: .background) } /// EZSE: Gobal queue with default priority - @available(*, deprecated: 1.7, renamed: "DispatchQueue.global()") + @available(*, deprecated, renamed: "DispatchQueue.global()") public var globalQueue: DispatchQueue { return DispatchQueue.global(qos: .default) } diff --git a/Sources/FloatingPointExtensions.swift b/Sources/FloatingPointExtensions.swift index bc3c8326..3325cca0 100644 --- a/Sources/FloatingPointExtensions.swift +++ b/Sources/FloatingPointExtensions.swift @@ -38,7 +38,7 @@ extension FloatingPoint { /// EZSE: Returns a random floating point number between 0.0 and 1.0, inclusive. public static func random() -> Float { - return Float(arc4random()) / 0xFFFFFFFF + return Float(arc4random()) / Float(0xFFFFFFFF) } /// EZSE: Returns a random floating point number in the range min...max, inclusive. diff --git a/Sources/IntExtensions.swift b/Sources/IntExtensions.swift index b7cf2ffd..a3e1bfe4 100644 --- a/Sources/IntExtensions.swift +++ b/Sources/IntExtensions.swift @@ -48,9 +48,8 @@ extension Int { return 1 } else if Int(fabs(Double(self))) <= LONG_MAX { return Int(log10(fabs(Double(self)))) + 1 - } else { - return -1; //out of bound } + return -1; //out of bound } /// EZSE: The digits of an integer represented in an array(from most significant to least). diff --git a/Sources/NSAttributedStringExtensions.swift b/Sources/NSAttributedStringExtensions.swift index 14b2ea11..034296f2 100644 --- a/Sources/NSAttributedStringExtensions.swift +++ b/Sources/NSAttributedStringExtensions.swift @@ -17,7 +17,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 +28,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 +39,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 +49,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 +62,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/NSDictionaryExtensions.swift b/Sources/NSDictionaryExtensions.swift index 9db5b809..783032e0 100644 --- a/Sources/NSDictionaryExtensions.swift +++ b/Sources/NSDictionaryExtensions.swift @@ -14,8 +14,8 @@ public extension NSDictionary { // MARK: - Deprecated 1.8 /// EZSE: Unserialize JSON string into NSDictionary - @available(*, deprecated: 1.8) - public convenience init ? (json: String) { + @available(*, deprecated) + convenience init ? (json: String) { if let data = (try? JSONSerialization.jsonObject(with: json.data(using: String.Encoding.utf8, allowLossyConversion: true)!, options: JSONSerialization.ReadingOptions.mutableContainers)) as? NSDictionary { self.init(dictionary: data) } else { @@ -25,8 +25,8 @@ public extension NSDictionary { } /// EZSE: Serialize NSDictionary into JSON string - @available(*, deprecated: 1.8) - public func formatJSON() -> String? { + @available(*, deprecated) + func formatJSON() -> String? { if let jsonData = try? JSONSerialization.data(withJSONObject: self, options: JSONSerialization.WritingOptions()) { let jsonStr = NSString(data: jsonData, encoding: String.Encoding.utf8.rawValue) return String(jsonStr ?? "") diff --git a/Sources/StringExtensions.swift b/Sources/StringExtensions.swift index 2bb103a2..2f0e2650 100644 --- a/Sources/StringExtensions.swift +++ b/Sources/StringExtensions.swift @@ -193,7 +193,7 @@ extension String { } /// EZSE: Counts whitespace & new lines - @available(*, deprecated: 1.6, renamed: "isBlank") + @available(*, deprecated, renamed: "isBlank") public func isOnlyEmptySpacesAndNewLineCharacters() -> Bool { let characterSet = CharacterSet.whitespacesAndNewlines let newText = self.trimmingCharacters(in: characterSet) @@ -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/UIColoredView.swift b/Sources/UIColoredView.swift index 2c445f87..60100b60 100644 --- a/Sources/UIColoredView.swift +++ b/Sources/UIColoredView.swift @@ -10,7 +10,7 @@ import UIKit -@available(*, deprecated: 1.8) +@available(*, deprecated) class UIColoredView: UIView { init() { super.init(frame: CGRect(x: 100, y: 100, w: 100, h: 100)) diff --git a/Sources/UIFontExtensions.swift b/Sources/UIFontExtensions.swift index 1541a1e0..94db66c1 100644 --- a/Sources/UIFontExtensions.swift +++ b/Sources/UIFontExtensions.swift @@ -96,7 +96,7 @@ extension UIFont { // MARK: Deprecated /// EZSwiftExtensions - @available(*, deprecated: 1.8) + @available(*, deprecated) public class func PrintFontFamily(_ font: FontName) { let arr = UIFont.fontNames(forFamilyName: font.rawValue) for name in arr { diff --git a/Sources/UIImageExtensions.swift b/Sources/UIImageExtensions.swift index c53678f0..ee283d27 100644 --- a/Sources/UIImageExtensions.swift +++ b/Sources/UIImageExtensions.swift @@ -13,18 +13,18 @@ import UIKit extension UIImage { /// EZSE: Returns base64 string - public var base64: String { - return UIImageJPEGRepresentation(self, 1.0)!.base64EncodedString() + public var base64: String? { + return 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 jpegData(compressionQuality: rate) } /// EZSE: Returns Image size in Bytes public func getSizeAsBytes() -> Int { - return UIImageJPEGRepresentation(self, 1)?.count ?? 0 + return jpegData(compressionQuality: 1)?.count ?? 0 } /// EZSE: Returns Image size in Kylobites @@ -89,7 +89,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/UIImageViewExtensions.swift b/Sources/UIImageViewExtensions.swift index deca299f..31bb2d3c 100644 --- a/Sources/UIImageViewExtensions.swift +++ b/Sources/UIImageViewExtensions.swift @@ -103,7 +103,7 @@ extension UIImageView { // MARK: Deprecated 1.8 /// EZSwiftExtensions - @available(*, deprecated: 1.8, renamed: "image(url:)") + @available(*, deprecated, renamed: "image(url:)") public func imageWithUrl(url: String) { ez.requestImage(url, success: { (image) -> Void in if let img = image { @@ -115,14 +115,14 @@ extension UIImageView { } /// EZSwiftExtensions - @available(*, deprecated: 1.8, renamed: "image(url:placeholder:)") + @available(*, deprecated, renamed: "image(url:placeholder:)") public func imageWithUrl(url: String, placeholder: UIImage) { self.image = placeholder imageWithUrl(url: url) } /// EZSwiftExtensions - @available(*, deprecated: 1.8, renamed: "image(url:placeholderNamed:)") + @available(*, deprecated, renamed: "image(url:placeholderNamed:)") public func imageWithUrl(url: String, placeholderNamed: String) { if let image = UIImage(named: placeholderNamed) { imageWithUrl(url: url, placeholder: image) 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..d7036dac 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,12 +275,12 @@ extension UIViewController { let imageView = UIImageView(frame: view.frame) imageView.image = image view.addSubview(imageView) - view.sendSubview(toBack: imageView) + view.sendSubviewToBack(imageView) } #if os(iOS) - @available(*, deprecated: 1.9) + @available(*, deprecated) public func hideKeyboardWhenTappedAroundAndCancelsTouchesInView() { let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(UIViewController.dismissKeyboard)) view.addGestureRecognizer(tap) 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