@ -1,11 +1,9 @@ |
|||||
# Uncomment the next line to define a global platform for your project |
platform :osx, '10.14' |
||||
# platform :ios, '9.0' |
|
||||
|
|
||||
target 'RSwitch' do |
target 'RSwitch' do |
||||
# Comment the next line if you don't want to use dynamic frameworks |
|
||||
use_frameworks! |
use_frameworks! |
||||
|
|
||||
# Pods for RSwitch |
|
||||
pod 'SwiftSoup' |
pod 'SwiftSoup' |
||||
|
|
||||
end |
end |
||||
|
Before Width: | Height: | Size: 8.0 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 25 KiB |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 2.7 KiB |
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 25 KiB |
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 64 KiB |
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 2.7 KiB |
Before Width: | Height: | Size: 4.3 KiB After Width: | Height: | Size: 5.4 KiB |
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 64 KiB |
Before Width: | Height: | Size: 69 KiB After Width: | Height: | Size: 152 KiB |
@ -0,0 +1,42 @@ |
|||||
|
// |
||||
|
// String+Version.swift |
||||
|
// Pods |
||||
|
// |
||||
|
// Created by DragonCherry on 5/11/17. |
||||
|
// |
||||
|
// |
||||
|
|
||||
|
import Foundation |
||||
|
|
||||
|
extension String { |
||||
|
|
||||
|
/// Inner comparison utility to handle same versions with different length. (Ex: "1.0.0" & "1.0") |
||||
|
private func compare(toVersion targetVersion: String) -> ComparisonResult { |
||||
|
|
||||
|
let versionDelimiter = "." |
||||
|
var result: ComparisonResult = .orderedSame |
||||
|
var versionComponents = components(separatedBy: versionDelimiter) |
||||
|
var targetComponents = targetVersion.components(separatedBy: versionDelimiter) |
||||
|
let spareCount = versionComponents.count - targetComponents.count |
||||
|
|
||||
|
if spareCount == 0 { |
||||
|
result = compare(targetVersion, options: .numeric) |
||||
|
} else { |
||||
|
let spareZeros = repeatElement("0", count: abs(spareCount)) |
||||
|
if spareCount > 0 { |
||||
|
targetComponents.append(contentsOf: spareZeros) |
||||
|
} else { |
||||
|
versionComponents.append(contentsOf: spareZeros) |
||||
|
} |
||||
|
result = versionComponents.joined(separator: versionDelimiter) |
||||
|
.compare(targetComponents.joined(separator: versionDelimiter), options: .numeric) |
||||
|
} |
||||
|
return result |
||||
|
} |
||||
|
|
||||
|
public func isVersion(equalTo targetVersion: String) -> Bool { return compare(toVersion: targetVersion) == .orderedSame } |
||||
|
public func isVersion(greaterThan targetVersion: String) -> Bool { return compare(toVersion: targetVersion) == .orderedDescending } |
||||
|
public func isVersion(greaterThanOrEqualTo targetVersion: String) -> Bool { return compare(toVersion: targetVersion) != .orderedAscending } |
||||
|
public func isVersion(lessThan targetVersion: String) -> Bool { return compare(toVersion: targetVersion) == .orderedAscending } |
||||
|
public func isVersion(lessThanOrEqualTo targetVersion: String) -> Bool { return compare(toVersion: targetVersion) != .orderedDescending } |
||||
|
} |