@ -1,11 +1,9 @@ |
|||
# Uncomment the next line to define a global platform for your project |
|||
# platform :ios, '9.0' |
|||
platform :osx, '10.14' |
|||
|
|||
target 'RSwitch' do |
|||
# Comment the next line if you don't want to use dynamic frameworks |
|||
|
|||
use_frameworks! |
|||
|
|||
# Pods for RSwitch |
|||
pod 'SwiftSoup' |
|||
|
|||
end |
|||
|
変更前 幅: | 高さ: | サイズ: 8.0 KiB 変更後 幅: | 高さ: | サイズ: 11 KiB |
変更前 幅: | 高さ: | サイズ: 16 KiB 変更後 幅: | 高さ: | サイズ: 25 KiB |
変更前 幅: | 高さ: | サイズ: 1.6 KiB 変更後 幅: | 高さ: | サイズ: 1.6 KiB |
変更前 幅: | 高さ: | サイズ: 2.6 KiB 変更後 幅: | 高さ: | サイズ: 2.7 KiB |
変更前 幅: | 高さ: | サイズ: 16 KiB 変更後 幅: | 高さ: | サイズ: 25 KiB |
変更前 幅: | 高さ: | サイズ: 32 KiB 変更後 幅: | 高さ: | サイズ: 64 KiB |
変更前 幅: | 高さ: | サイズ: 2.6 KiB 変更後 幅: | 高さ: | サイズ: 2.7 KiB |
変更前 幅: | 高さ: | サイズ: 4.3 KiB 変更後 幅: | 高さ: | サイズ: 5.4 KiB |
変更前 幅: | 高さ: | サイズ: 32 KiB 変更後 幅: | 高さ: | サイズ: 64 KiB |
変更前 幅: | 高さ: | サイズ: 69 KiB 変更後 幅: | 高さ: | サイズ: 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 } |
|||
} |