Skip to content

Commit

Permalink
Merge branch 'deploy/2.7.1' into productive
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeehut committed Nov 10, 2018
2 parents dfa0f27 + 0f0223d commit bbbcebc
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 67 deletions.
3 changes: 1 addition & 2 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ opt_in_rules:
- empty_xctest_method
- explicit_init
- explicit_type_interface
- extension_access_modifier
- fallthrough
- fatal_error_message
- file_header
Expand Down Expand Up @@ -71,7 +70,7 @@ disabled_rules:
- type_name

included:
- Sources
- Frameworks
- Tests

excluded:
Expand Down
4 changes: 2 additions & 2 deletions Frameworks/HandySwift/Extensions/ArrayExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ extension Array {

func merge(low: Int, mid: Int, high: Int) {
tmp.removeAll(keepingCapacity: true)
tmp.append(contentsOf: self[low..<high])
tmp.append(contentsOf: self[low ..< high])

var i = 0, j = mid - low // swiftlint:disable:this identifier_name
let iMax = j, jMax = tmp.count

for k in low..<high { // swiftlint:disable:this identifier_name
for k in low ..< high { // swiftlint:disable:this identifier_name
let tmpPosIsJ = i == iMax || (j != jMax && areInIncreasingOrder(tmp[j], tmp[i]))
self[k] = tmp[tmpPosIsJ ? j : i]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ extension DispatchTimeInterval {
/// - Returns: The time in seconds using the`TimeInterval` type.
public var timeInterval: TimeInterval {
switch self {
case .seconds(let seconds):
case let .seconds(seconds):
return Double(seconds)

case .milliseconds(let milliseconds):
case let .milliseconds(milliseconds):
return Double(milliseconds) / Timespan.millisecondsPerSecond

case .microseconds(let microseconds):
case let .microseconds(microseconds):
return Double(microseconds) / Timespan.microsecondsPerSecond

case .nanoseconds(let nanoseconds):
case let .nanoseconds(nanoseconds):
return Double(nanoseconds) / Timespan.nanosecondsPerSecond

case .never:
Expand Down
4 changes: 2 additions & 2 deletions Frameworks/HandySwift/Extensions/IntExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extension Int {
/// - closure: The code to be run multiple times.
public func times(_ closure: () -> Void) {
guard self > 0 else { return }
for _ in 0..<self { closure() }
for _ in 0 ..< self { closure() }
}

/// Runs the code passed as a closure the specified number of times
Expand All @@ -31,6 +31,6 @@ extension Int {
/// - closure: The code to deliver a return value multiple times.
public func timesMake<ReturnType>(_ closure: () -> ReturnType) -> [ReturnType] {
guard self > 0 else { return [] }
return (0..<self).map { _ in return closure() }
return (0 ..< self).map { _ in return closure() }
}
}
22 changes: 11 additions & 11 deletions Frameworks/HandySwift/Extensions/StringExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@
import Foundation

extension String {
/// - Returns: `true` if contains any cahracters other than whitespace or newline characters, else `no`.
public var isBlank: Bool { return stripped().isEmpty }

/// Returns a random character from the String.
///
/// - Returns: A random character from the String or `nil` if empty.
public var sample: Character? {
return isEmpty ? nil : self[index(startIndex, offsetBy: Int(randomBelow: count)!)]
}

/// Create new instance with random numeric/alphabetic/alphanumeric String of given length.
///
/// - Parameters:
Expand All @@ -23,27 +33,17 @@ extension String {
case .alphaNumeric:
return "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"

case .allCharactersIn(let allowedCharactersString):
case let .allCharactersIn(allowedCharactersString):
return allowedCharactersString
}
}()

self.init(allowedCharsString.sample(size: length)!)
}

/// - Returns: `true` if contains any cahracters other than whitespace or newline characters, else `no`.
public var isBlank: Bool { return stripped().isEmpty }

/// - Returns: The string stripped by whitespace and newline characters from beginning and end.
public func stripped() -> String { return trimmingCharacters(in: .whitespacesAndNewlines) }

/// Returns a random character from the String.
///
/// - Returns: A random character from the String or `nil` if empty.
public var sample: Character? {
return isEmpty ? nil : self[index(startIndex, offsetBy: Int(randomBelow: count)!)]
}

/// Returns a given number of random characters from the String.
///
/// - Parameters:
Expand Down
10 changes: 5 additions & 5 deletions Frameworks/HandySwift/Structs/FrequencyTable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ public struct FrequencyTable<T> {
/// Contains all values the amount of time of their frequencies.
private let frequentValues: [T]

// MARK: - Computed Instance Properties
/// - Returns: A random value taking frequencies into account or nil if values empty.
public var sample: T? { return frequentValues.sample }

// MARK: - Initializers
/// Creates a new FrequencyTable instance with values and their frequencies provided.
///
Expand All @@ -29,10 +33,6 @@ public struct FrequencyTable<T> {
}
}

// MARK: - Computed Instance Properties
/// - Returns: A random value taking frequencies into account or nil if values empty.
public var sample: T? { return frequentValues.sample }

// MARK: - Instance Methods
/// Returns an array of random values taking frequencies into account or nil if values empty.
///
Expand All @@ -42,6 +42,6 @@ public struct FrequencyTable<T> {
/// - Returns: An array of random values or nil if values empty.
public func sample(size: Int) -> [T]? {
guard size > 0 && !frequentValues.isEmpty else { return nil }
return Array(0..<size).map { _ in sample! }
return Array(0 ..< size).map { _ in sample! }
}
}
2 changes: 1 addition & 1 deletion Frameworks/HandySwift/Structs/Regex.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public struct Regex {
public func replacingMatches(in input: String, with template: String, count: Int? = nil) -> String {
var output = input
let matches = self.matches(in: input)
let rangedMatches = Array(matches[0..<min(matches.count, count ?? .max)])
let rangedMatches = Array(matches[0 ..< min(matches.count, count ?? .max)])
for match in rangedMatches.reversed() {
let replacement = match.string(applyingTemplate: template)
output.replaceSubrange(match.range, with: replacement)
Expand Down
42 changes: 22 additions & 20 deletions Frameworks/HandySwift/Structs/SortedArray.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public struct SortedArray<Element: Comparable> {
public func index(where predicate: (Element) -> Bool) -> Int? {
// cover trivial cases
guard !array.isEmpty else { return nil }
if let first = array.first, predicate(first) { return array.startIndex } // swiftlint:disable:this if_as_guard
if let last = array.last, !predicate(last) { return nil } // swiftlint:disable:this if_as_guard
if let first = array.first, predicate(first) { return array.startIndex }
if let last = array.last, !predicate(last) { return nil }

// binary search for first matching element
var foundMatch = false
Expand Down Expand Up @@ -105,14 +105,6 @@ public struct SortedArray<Element: Comparable> {
return SortedArray(sequence: subarray, preSorted: true)
}

/// Accesses a contiguous subrange of the SortedArray's elements.
///
/// - Parameter
/// - bounds: A range of the SortedArray's indices. The bounds of the range must be valid indices.
public subscript(bounds: Range<Int>) -> SortedArray {
return SortedArray(sequence: array[bounds], preSorted: true)
}

// MARK: - Mutating Methods
/// Adds a new item to the sorted array.
///
Expand Down Expand Up @@ -144,18 +136,18 @@ public struct SortedArray<Element: Comparable> {
public mutating func remove(at index: Int) {
internalArray.remove(at: index)
}
}

extension SortedArray: Collection { // swiftlint:disable missing_docs
public typealias Index = Array<Element>.Index

public func index(after index: Int) -> Int {
return internalArray.index(after: index)
/// Accesses a contiguous subrange of the SortedArray's elements.
///
/// - Parameter
/// - bounds: A range of the SortedArray's indices. The bounds of the range must be valid indices.
public subscript(bounds: Range<Int>) -> SortedArray {
return SortedArray(sequence: array[bounds], preSorted: true)
}
}

public subscript(position: Int) -> Element {
return internalArray[position]
}
extension SortedArray: Collection {
public typealias Index = Array<Element>.Index

public var startIndex: Int {
return internalArray.startIndex
Expand All @@ -168,4 +160,14 @@ extension SortedArray: Collection { // swiftlint:disable missing_docs
public func sorted() -> [Element] {
return internalArray
}
} // swiftlint:enable missing_docs

public func index(after index: Int) -> Int {
return internalArray.index(after: index)
}

public subscript(position: Int) -> Element {
return internalArray[position]
}
}

extension SortedArray: Codable where Element: Codable {}
10 changes: 5 additions & 5 deletions Frameworks/HandySwift/Structs/Weak.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ public struct Weak<Wrapped>: ExpressibleByNilLiteral where Wrapped: AnyObject {
self.value = value
}

/// Creates an instance initialized with `nil`.
public init(nilLiteral: ()) {
self.value = nil
}

/// Evaluates the given closure when this `Weak` instance is not `nil`,
/// passing the value as a parameter.
///
Expand All @@ -40,11 +45,6 @@ public struct Weak<Wrapped>: ExpressibleByNilLiteral where Wrapped: AnyObject {

return try transform(value)
}

/// Creates an instance initialized with `nil`.
public init(nilLiteral: ()) {
self.value = nil
}
}

extension Weak: CustomDebugStringConvertible {
Expand Down
3 changes: 2 additions & 1 deletion Frameworks/SupportingFiles/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>2.7.0</string>
<string>2.7.1
</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
5 changes: 3 additions & 2 deletions HandySwift.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
Pod::Spec.new do |s|

s.name = "HandySwift"
s.version = "2.7.0"
s.version = "2.7.1
"
s.summary = "Handy Swift features that didn't make it into the Swift standard library"

s.description = <<-DESC
Expand All @@ -21,7 +22,7 @@ Pod::Spec.new do |s|
s.tvos.deployment_target = "9.0"

s.source = { :git => "https://github.com/Flinesoft/HandySwift.git", :tag => "#{s.version}" }
s.source_files = "Sources", "Framework/Sources/**/*.swift"
s.source_files = "Frameworks/HandySwift/**/*.swift"
s.framework = "Foundation"
s.swift_version = "4.2"

Expand Down
13 changes: 3 additions & 10 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,18 @@ import PackageDescription
let package = Package(
name: "HandySwift",
products: [
.library(
name: "HandySwift",
targets: ["HandySwift"]
)
.library(name: "HandySwift", targets: ["HandySwift"])
],
targets: [
.target(
name: "HandySwift",
path: "Frameworks/HandySwift",
exclude: [
"Frameworks/SupportingFiles"
]
exclude: ["Frameworks/SupportingFiles"]
),
.testTarget(
name: "HandySwiftTests",
dependencies: ["HandySwift"],
exclude: [
"Tests/SupportingFiles"
]
exclude: ["Tests/SupportingFiles"]
)
],
swiftLanguageVersions: [4]
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
alt="Codebeat Status">
</a>
<a href="https://github.com/Flinesoft/HandySwift/releases">
<img src="https://img.shields.io/badge/Version-2.7.0-blue.svg"
alt="Version: 2.7.0">
<img src="https://img.shields.io/badge/Version-2.7.1
-blue.svg"
alt="Version: 2.7.1
">
</a>
<img src="https://img.shields.io/badge/Swift-4.2-FFAC45.svg"
alt="Swift: 4.2">
Expand Down

0 comments on commit bbbcebc

Please sign in to comment.