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 #500

Open
wants to merge 2 commits 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
5 changes: 3 additions & 2 deletions EZSwiftExtensions.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
);
mainGroup = B5DC869F1C0ED06700972D0A;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
6 changes: 3 additions & 3 deletions EZSwiftExtensions/UIStackViewExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 15 additions & 15 deletions Sources/ArrayExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ extension Array {

///EZSE: Get a sub array from range of index
public func get(at range: ClosedRange<Int>) -> Array {
let halfOpenClampedRange = Range(range).clamped(to: Range(indices))
let halfOpenClampedRange = Range(range).clamped(to: indices)
return Array(self[halfOpenClampedRange])
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<T>(_ 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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}

}
Expand All @@ -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<V>(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)
}
Expand Down
16 changes: 8 additions & 8 deletions Sources/BlockButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion Sources/BlockLongPress.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/BlockSwipe.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ open class BlockSwipe: UISwipeGestureRecognizer {
}

public convenience init (
direction: UISwipeGestureRecognizerDirection,
direction: UISwipeGestureRecognizer.Direction,
fingerCount: Int = 1,
action: ((UISwipeGestureRecognizer) -> Void)?) {
self.init()
Expand Down
2 changes: 1 addition & 1 deletion Sources/BlockWebView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions Sources/BundleExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(_ name: String) -> T? {
class func loadNib<T>(_ name: String) -> T? {
return Bundle.main.loadNibNamed(name, owner: nil, options: nil)?[0] as? T
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/CGFloatExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions Sources/DoubleExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
24 changes: 12 additions & 12 deletions Sources/EZSwiftFunctions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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()
}
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/FloatingPointExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions Sources/IntExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
Loading