You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
1008 B
33 lines
1008 B
//
|
|
// VersionComparator.swift
|
|
// PadelClub
|
|
//
|
|
// Created by Laurent Morvillier on 13/02/2025.
|
|
//
|
|
|
|
class VersionComparator {
|
|
|
|
static func compare(_ version1: String, _ version2: String) -> Int {
|
|
// Split versions into components
|
|
let v1Components = version1.split(separator: ".").map { Int($0) ?? 0 }
|
|
let v2Components = version2.split(separator: ".").map { Int($0) ?? 0 }
|
|
|
|
// Get the maximum length to compare
|
|
let maxLength = max(v1Components.count, v2Components.count)
|
|
|
|
// Compare each component
|
|
for i in 0..<maxLength {
|
|
let v1Num = i < v1Components.count ? v1Components[i] : 0
|
|
let v2Num = i < v2Components.count ? v2Components[i] : 0
|
|
|
|
if v1Num < v2Num {
|
|
return -1 // version1 is smaller
|
|
} else if v1Num > v2Num {
|
|
return 1 // version1 is larger
|
|
}
|
|
}
|
|
|
|
return 0 // versions are equal
|
|
}
|
|
|
|
}
|
|
|