Skip to content

Instantly share code, notes, and snippets.

@lfarah
Created October 12, 2016 19:39
Show Gist options
  • Save lfarah/c24a87b55cc317255b3cb05c59e0f1b6 to your computer and use it in GitHub Desktop.
Save lfarah/c24a87b55cc317255b3cb05c59e0f1b6 to your computer and use it in GitHub Desktop.
import UIKit
extension String {
func isNewerThan(update: String) -> Bool {
let arrayDotsStr = self.components(separatedBy: ".")
var arrayDotsInt: [Int] = []
for char in arrayDotsStr {
arrayDotsInt.append(Int(char)!)
}
let arrayDotsStr2 = update.components(separatedBy: ".")
var arrayDotsInt2: [Int] = []
for char in arrayDotsStr2 {
arrayDotsInt2.append(Int(char)!)
}
let smallestArray = arrayDotsInt.count < arrayDotsInt2.count ? arrayDotsInt : arrayDotsInt2
let otherArray = smallestArray != arrayDotsInt ? arrayDotsInt : arrayDotsInt2
for item in smallestArray {
if item == otherArray[smallestArray.index(of: item)!] {
if smallestArray.count < otherArray.count && smallestArray.index(of: item) == smallestArray.count - 1 {
print(otherArray)
return otherArray == arrayDotsInt
}
} else {
let biggestVersion = item > otherArray[smallestArray.index(of: item)!] ? smallestArray : otherArray
print(biggestVersion)
return biggestVersion == arrayDotsInt
}
}
print("Equal")
return false
}
}
"10.3.5".isNewerThan(update: "10.3.5")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment