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

Surport Swift 5 #499

Closed
wants to merge 1 commit into from
Closed
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
11 changes: 7 additions & 4 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 @@ -1350,7 +1351,7 @@
SDKROOT = macosx;
SKIP_INSTALL = YES;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -1374,7 +1375,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 5.0;
};
name = Release;
};
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 = 5.0;
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 = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand Down Expand Up @@ -1590,6 +1591,7 @@
PRODUCT_NAME = EZSwiftExtensions;
SDKROOT = appletvos;
SKIP_INSTALL = YES;
SWIFT_VERSION = 5.0;
TVOS_DEPLOYMENT_TARGET = 9.0;
};
name = Debug;
Expand All @@ -1609,6 +1611,7 @@
PRODUCT_NAME = EZSwiftExtensions;
SDKROOT = appletvos;
SKIP_INSTALL = YES;
SWIFT_VERSION = 5.0;
TVOS_DEPLOYMENT_TARGET = 9.0;
};
name = Release;
Expand Down
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
8 changes: 6 additions & 2 deletions EZSwiftExtensionsExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@
TargetAttributes = {
E1839DB41BF79335002212C6 = {
CreatedOnToolsVersion = 7.0.1;
DevelopmentTeam = Y8MK4UJH8L;
LastSwiftMigration = 0800;
};
};
Expand All @@ -260,6 +261,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
Base,
);
Expand Down Expand Up @@ -462,25 +464,27 @@
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;
};
E1839DC91BF79335002212C6 /* Release */ = {
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;
};
Expand Down
2 changes: 1 addition & 1 deletion 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
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
46 changes: 23 additions & 23 deletions Sources/DateExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we commenting this out?

//
// 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()
Expand Down
8 changes: 4 additions & 4 deletions Sources/EZSwiftFunctions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
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 == .portrait || screenOrientation == .portraitUpsideDown {
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
1 change: 1 addition & 0 deletions Sources/IntExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import Foundation
import AVFoundation
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this ?


extension Int {
/// EZSE: Checks if the integer is even.
Expand Down
12 changes: 7 additions & 5 deletions Sources/NSAttributedStringExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
// Copyright (c) 2016 Lucas Farah. All rights reserved.
//

import Foundation

#if os(iOS) || os(tvOS)

extension NSAttributedString {
Expand All @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
Expand All @@ -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
}
}
Expand Down
2 changes: 2 additions & 0 deletions Sources/NSObjectExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
// Copyright (c) 2015 Goktug Yilmaz. All rights reserved.
//

import Foundation
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this ?


#if os(iOS) || os(tvOS)

extension NSObject {
Expand Down
14 changes: 7 additions & 7 deletions Sources/StringExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
}

Expand All @@ -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)
Expand All @@ -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
}

Expand All @@ -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
}
Expand Down
Loading