Skip to content

Commit

Permalink
Bugfix: XcodesOrg#382 The display order of the Xcode version list is …
Browse files Browse the repository at this point in the history
…disordered and some duplicated
  • Loading branch information
wangzhizhou committed Aug 22, 2024
1 parent 74516ad commit 073de69
Showing 1 changed file with 38 additions and 16 deletions.
54 changes: 38 additions & 16 deletions Sources/XcodesKit/XcodeInstaller.swift
Original file line number Diff line number Diff line change
Expand Up @@ -540,26 +540,48 @@ public final class XcodeInstaller {
.done { output in
let selectedInstalledXcodeVersion = installedXcodes.first { output.out.hasPrefix($0.path.string) }.map { $0.version }

allXcodeVersions
.sorted { first, second -> Bool in
// Sort prereleases by release date, otherwise sort by version
if first.version.isPrerelease, second.version.isPrerelease, let firstDate = first.releaseDate, let secondDate = second.releaseDate {
return firstDate < secondDate
}
return first.version < second.version
// unique and sorted all xcode versions
allXcodeVersions.enumerated().filter { index, releasedVersion -> Bool in
index == allXcodeVersions.firstIndex {
releasedVersion.version == $0.version &&
releasedVersion.version.isPrerelease == $0.version.isPrerelease &&
releasedVersion.version.appleDescriptionWithBuildIdentifier == $0.version.appleDescriptionWithBuildIdentifier
}
.forEach { releasedVersion in
var output = releasedVersion.version.appleDescriptionWithBuildIdentifier
if installedXcodes.contains(where: { releasedVersion.version.isEquivalent(to: $0.version) }) {
if releasedVersion.version == selectedInstalledXcodeVersion {
output += " (\("Installed".blue), \("Selected".green))"
}
else {
output += " (\("Installed".blue))"
}.map{
$0.element
}.sorted { first, second -> Bool in

let predicates: [(ReleasedVersion, ReleasedVersion) -> Bool] = [
{ $0.version < $1.version },
{
if let firstDate = $0.releaseDate, let secondDate = $1.releaseDate {
return firstDate < secondDate
} else {
return false
}
}
Current.logging.log(output)
]

for predicate in predicates {
if !predicate(first, second) && !predicate(second, first) {
continue
}
return predicate(first, second)
}

return false
}.forEach { releasedVersion in
var output = releasedVersion.version.appleDescriptionWithBuildIdentifier
if installedXcodes.contains(where: { releasedVersion.version.isEquivalent(to: $0.version) }) {
if releasedVersion.version == selectedInstalledXcodeVersion {
output += " (\("Installed".blue), \("Selected".green))"
}
else {
output += " (\("Installed".blue))"
}
}
Current.logging.log(output)
}
}
}

Expand Down

0 comments on commit 073de69

Please sign in to comment.