Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #382: The display order of the Xcode version list is disordered and some duplicated #383

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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