From 30a6419f0e66a092495d40741dcc2aa00591cfa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cihat=20Gu=CC=88ndu=CC=88z?= Date: Thu, 27 Sep 2018 19:52:41 +0200 Subject: [PATCH 1/5] Fix SwiftLint configuration issue + Package.swift cleanup --- .swiftlint.yml | 2 +- Package.swift | 13 +++---------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/.swiftlint.yml b/.swiftlint.yml index 6443cf1..6fb9c37 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -71,7 +71,7 @@ disabled_rules: - type_name included: -- Sources +- Frameworks - Tests excluded: diff --git a/Package.swift b/Package.swift index 0a97285..46648b4 100644 --- a/Package.swift +++ b/Package.swift @@ -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] From 783705424f578fc857be8cc0aeaa781a85333c7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cihat=20Gu=CC=88ndu=CC=88z?= Date: Thu, 1 Nov 2018 13:32:17 +0100 Subject: [PATCH 2/5] Update Podspec --- HandySwift.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HandySwift.podspec b/HandySwift.podspec index cf72d75..2048e8b 100644 --- a/HandySwift.podspec +++ b/HandySwift.podspec @@ -21,7 +21,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" From ef0001278ff0af09b755c8118d9515d4b6485eee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cihat=20Gu=CC=88ndu=CC=88z?= Date: Sat, 10 Nov 2018 13:52:27 +0100 Subject: [PATCH 3/5] Fix many SwiftLint warnings --- .swiftlint.yml | 1 - .../Extensions/ArrayExtension.swift | 4 +- .../DispatchTimeIntervalExtension.swift | 8 ++-- .../HandySwift/Extensions/IntExtension.swift | 4 +- .../Extensions/StringExtension.swift | 22 +++++----- .../HandySwift/Structs/FrequencyTable.swift | 10 ++--- Frameworks/HandySwift/Structs/Regex.swift | 2 +- .../HandySwift/Structs/SortedArray.swift | 40 +++++++++---------- Frameworks/HandySwift/Structs/Weak.swift | 10 ++--- 9 files changed, 50 insertions(+), 51 deletions(-) diff --git a/.swiftlint.yml b/.swiftlint.yml index 6fb9c37..8315e41 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -12,7 +12,6 @@ opt_in_rules: - empty_xctest_method - explicit_init - explicit_type_interface -- extension_access_modifier - fallthrough - fatal_error_message - file_header diff --git a/Frameworks/HandySwift/Extensions/ArrayExtension.swift b/Frameworks/HandySwift/Extensions/ArrayExtension.swift index 6ca16fd..25aa1f1 100644 --- a/Frameworks/HandySwift/Extensions/ArrayExtension.swift +++ b/Frameworks/HandySwift/Extensions/ArrayExtension.swift @@ -79,12 +79,12 @@ extension Array { func merge(low: Int, mid: Int, high: Int) { tmp.removeAll(keepingCapacity: true) - tmp.append(contentsOf: self[low.. Void) { guard self > 0 else { return } - for _ in 0..(_ closure: () -> ReturnType) -> [ReturnType] { guard self > 0 else { return [] } - return (0.. 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: diff --git a/Frameworks/HandySwift/Structs/FrequencyTable.swift b/Frameworks/HandySwift/Structs/FrequencyTable.swift index dc87287..ec242ff 100644 --- a/Frameworks/HandySwift/Structs/FrequencyTable.swift +++ b/Frameworks/HandySwift/Structs/FrequencyTable.swift @@ -16,6 +16,10 @@ public struct FrequencyTable { /// 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. /// @@ -29,10 +33,6 @@ public struct FrequencyTable { } } - // 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. /// @@ -42,6 +42,6 @@ public struct FrequencyTable { /// - 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.. String { var output = input let matches = self.matches(in: input) - let rangedMatches = Array(matches[0.. { 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 @@ -105,14 +105,6 @@ public struct SortedArray { 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) -> SortedArray { - return SortedArray(sequence: array[bounds], preSorted: true) - } - // MARK: - Mutating Methods /// Adds a new item to the sorted array. /// @@ -144,18 +136,18 @@ public struct SortedArray { public mutating func remove(at index: Int) { internalArray.remove(at: index) } -} -extension SortedArray: Collection { // swiftlint:disable missing_docs - public typealias Index = Array.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) -> SortedArray { + return SortedArray(sequence: array[bounds], preSorted: true) } +} - public subscript(position: Int) -> Element { - return internalArray[position] - } +extension SortedArray: Collection { + public typealias Index = Array.Index public var startIndex: Int { return internalArray.startIndex @@ -168,4 +160,12 @@ 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] + } +} diff --git a/Frameworks/HandySwift/Structs/Weak.swift b/Frameworks/HandySwift/Structs/Weak.swift index 878352a..4aaf0b6 100644 --- a/Frameworks/HandySwift/Structs/Weak.swift +++ b/Frameworks/HandySwift/Structs/Weak.swift @@ -15,6 +15,11 @@ public struct Weak: 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. /// @@ -40,11 +45,6 @@ public struct Weak: ExpressibleByNilLiteral where Wrapped: AnyObject { return try transform(value) } - - /// Creates an instance initialized with `nil`. - public init(nilLiteral: ()) { - self.value = nil - } } extension Weak: CustomDebugStringConvertible { From 898ab39a08ff8a0040fb94811198c72d8f87e87a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cihat=20Gu=CC=88ndu=CC=88z?= Date: Sat, 10 Nov 2018 13:55:23 +0100 Subject: [PATCH 4/5] Make SortedArray conform to Codable if Element is, too --- Frameworks/HandySwift/Structs/SortedArray.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Frameworks/HandySwift/Structs/SortedArray.swift b/Frameworks/HandySwift/Structs/SortedArray.swift index d2a7bba..30a4c10 100644 --- a/Frameworks/HandySwift/Structs/SortedArray.swift +++ b/Frameworks/HandySwift/Structs/SortedArray.swift @@ -169,3 +169,5 @@ extension SortedArray: Collection { return internalArray[position] } } + +extension SortedArray: Codable where Element: Codable {} From 0f0223de2d03ea0fef1c850410b8bfb86c9190d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cihat=20Gu=CC=88ndu=CC=88z?= Date: Sat, 10 Nov 2018 13:56:23 +0100 Subject: [PATCH 5/5] Bump version num --- Frameworks/SupportingFiles/Info.plist | 3 ++- HandySwift.podspec | 3 ++- README.md | 6 ++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Frameworks/SupportingFiles/Info.plist b/Frameworks/SupportingFiles/Info.plist index febd1af..111577c 100644 --- a/Frameworks/SupportingFiles/Info.plist +++ b/Frameworks/SupportingFiles/Info.plist @@ -15,7 +15,8 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 2.7.0 + 2.7.1 + CFBundleSignature ???? CFBundleVersion diff --git a/HandySwift.podspec b/HandySwift.podspec index 2048e8b..b717f75 100644 --- a/HandySwift.podspec +++ b/HandySwift.podspec @@ -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 diff --git a/README.md b/README.md index 853ecda..a40ca06 100644 --- a/README.md +++ b/README.md @@ -13,8 +13,10 @@ alt="Codebeat Status"> - Version: 2.7.0 + Version: 2.7.1
+ Swift: 4.2