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

Swift5.0 #503

Merged
merged 5 commits into from Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .swift-version
@@ -1 +1 @@
4.0
5.0
8 changes: 4 additions & 4 deletions .travis.yml
@@ -1,4 +1,4 @@
osx_image: xcode10.2
osx_image: xcode10.2.1
language: objective-c
rvm: 2.2.2
cache: cocoapods
Expand All @@ -22,13 +22,13 @@ before_script:

script:
- set -o pipefail

- xcodebuild clean build test -project "$PROJECT" -scheme EZSwiftExtensions-iOS -destination 'platform=iOS Simulator,name=iPhone 5s,OS=10.3.1' | XCPRETTY_JSON_FILE_OUTPUT="xcodebuild-ios.json" xcpretty -f `xcpretty-json-formatter`
- xcodebuild clean build test -project "$PROJECT" -scheme EZSwiftExtensions-tvOS -destination 'platform=tvOS Simulator,name=Apple TV 1080p,OS=10.0' | XCPRETTY_JSON_FILE_OUTPUT="xcodebuild-tvos.json" xcpretty -f `xcpretty-json-formatter`
- xcodebuild clean build test -project "$PROJECT" -scheme EZSwiftExtensions-macOS -destination 'platform=macOS,arch=x86_64' | XCPRETTY_JSON_FILE_OUTPUT="xcodebuild-macos.json" xcpretty -f `xcpretty-json-formatter`

- pod lib lint
- bundle exec danger --fail-on-errors=true

after_success:
- bash <(curl -s https://codecov.io/bash)
6 changes: 3 additions & 3 deletions EZSwiftExtensions.podspec
@@ -1,18 +1,18 @@
Pod::Spec.new do |s|
s.name = "EZSwiftExtensions"
s.version = "2.0"
s.version = "2.1"
s.summary = ":smirk: How Swift standard types and classes were supposed to work"
s.description = ":smirk: How Swift standard types and classes were supposed to work."
s.homepage = "https://github.com/goktugyil/EZSwiftExtensions"
s.license = 'MIT'
s.author = { "goktugyil" => "gok-2@hotmail.com" }
s.source = { :git => "https://github.com/goktugyil/EZSwiftExtensions.git", :tag => s.version.to_s }
s.ios.deployment_target = '8.0'
s.ios.deployment_target = '9.0'
s.tvos.deployment_target = '9.0'
s.osx.deployment_target = '10.11'
s.requires_arc = true

# If more than one source file: https://guides.cocoapods.org/syntax/podspec.html#source_files
s.source_files = 'Sources/*.swift'
s.source_files = 'Sources/*.swift'

end
2 changes: 2 additions & 0 deletions EZSwiftExtensions.xcodeproj/project.pbxproj
Expand Up @@ -1632,6 +1632,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.gbf.EZSwiftExtensions.EZSwiftExtensionsTests;
PRODUCT_NAME = EZSwiftExtensionsTest;
SDKROOT = appletvos;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -1643,6 +1644,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.gbf.EZSwiftExtensions.EZSwiftExtensionsTests;
PRODUCT_NAME = EZSwiftExtensionsTest;
SDKROOT = appletvos;
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand Down
@@ -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>
32 changes: 16 additions & 16 deletions Sources/ArrayExtensions.swift
Expand Up @@ -104,17 +104,17 @@ extension Array where Element: Equatable {

/// EZSE: Checks if the main array contains the parameter array
public func contains(_ array: [Element]) -> Bool {
return array.testAll { self.index(of: $0) ?? -1 >= 0 }
return array.testAll { self.firstIndex(of: $0) ?? -1 >= 0 }
}

/// EZSE: Checks if self contains a list of items.
public func contains(_ elements: Element...) -> Bool {
return elements.testAll { self.index(of: $0) ?? -1 >= 0 }
return elements.testAll { self.firstIndex(of: $0) ?? -1 >= 0 }
}

/// 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 All @@ -124,7 +124,7 @@ extension Array where Element: Equatable {

/// EZSE: Removes the first given object
public mutating func removeFirst(_ element: Element) {
guard let index = index(of: element) else { return }
guard let index = firstIndex(of: element) else { return }
self.remove(at: index)
}

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: "get(at:)")
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: "testAll(is:)")
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,25 +273,25 @@ 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)
}
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
43 changes: 18 additions & 25 deletions Sources/DateExtensions.swift
Expand Up @@ -15,31 +15,23 @@ class DateFormattersManager {
}

extension Date {

public static let minutesInAWeek = 24 * 60 * 7

/// EZSE: Initializes Date from string and format
public init?(fromString string: String,
format: String,
timezone: TimeZone = TimeZone.autoupdatingCurrent,
locale: Locale = Locale.current) {
if let dateFormatter = DateFormattersManager.dateFormatters.getValue(for: format) {
if let date = dateFormatter.date(from: string) {
self = date
} else {
return nil
}

let formatter = DateFormatter()
formatter.timeZone = timezone
formatter.locale = locale
formatter.dateFormat = format
if let date = formatter.date(from: string) {
self = date
} else {
let formatter = DateFormatter()
formatter.timeZone = timezone
formatter.locale = locale
formatter.dateFormat = format
DateFormattersManager.dateFormatters.setValue(for: format, value: formatter)
if let date = formatter.date(from: string) {
self = date
} else {
return nil
}
return nil
}
}

Expand Down Expand Up @@ -146,7 +138,7 @@ extension Date {
let calendar = Calendar.autoupdatingCurrent
let components = (calendar as NSCalendar).components([.year, .month, .day, .hour, .minute, .second], from: self, to: date, options: [])
var str: String

if components.year! >= 1 {
components.year == 1 ? (str = "year") : (str = "years")
return "\(components.year!) \(str) ago"
Expand All @@ -169,8 +161,9 @@ extension Date {
return "Just now"
}
}

/// EZSE: Easy creation of time passed String. Can be Years, Months, days, hours, minutes or seconds. Useful for localization
/// I don't know how to fix this bug. if someone know, please pull request
// public func timePassed() -> TimePassed {
//
// let date = Date()
Expand Down Expand Up @@ -198,7 +191,7 @@ extension Date {
public var isFuture: Bool {
return self > Date()
}

/// EZSE: Check if date is in past.
public var isPast: Bool {
return self < Date()
Expand Down Expand Up @@ -243,7 +236,7 @@ extension Date {
public var era: Int {
return Calendar.current.component(Calendar.Component.era, from: self)
}

/// EZSE : Get the year from the date
public var year: Int {
return Calendar.current.component(Calendar.Component.year, from: self)
Expand Down Expand Up @@ -287,21 +280,21 @@ extension Date {
public var second: Int {
return Calendar.current.component(.second, from: self)
}

/// EZSE : Gets the nano second from the date
public var nanosecond: Int {
return Calendar.current.component(.nanosecond, from: self)
}

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

/// EZSE : Gets the international standard(ISO8601) representation of date
@available(iOS 10.0, *)
@available(tvOS 10.0, *)
public var iso8601: String {
let formatter = ISO8601DateFormatter()
return formatter.string(from: self)
}

#endif
}
12 changes: 8 additions & 4 deletions Sources/DoubleExtensions.swift
Expand Up @@ -8,6 +8,10 @@

import Foundation

#if os(iOS) || os(tvOS)
import UIKit
#endif

precedencegroup PowerPrecedence { higherThan: MultiplicationPrecedence }
infix operator ** : PowerPrecedence

Expand Down Expand Up @@ -37,25 +41,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