Skip to content

Commit 1750a1f

Browse files
author
wangzhizhou
committed
Bugfix: #382 The display order of the Xcode version list is disordered and some duplicated
1 parent 93bce87 commit 1750a1f

File tree

1 file changed

+38
-16
lines changed

1 file changed

+38
-16
lines changed

Sources/XcodesKit/XcodeInstaller.swift

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -540,26 +540,48 @@ public final class XcodeInstaller {
540540
.done { output in
541541
let selectedInstalledXcodeVersion = installedXcodes.first { output.out.hasPrefix($0.path.string) }.map { $0.version }
542542

543-
allXcodeVersions
544-
.sorted { first, second -> Bool in
545-
// Sort prereleases by release date, otherwise sort by version
546-
if first.version.isPrerelease, second.version.isPrerelease, let firstDate = first.releaseDate, let secondDate = second.releaseDate {
547-
return firstDate < secondDate
548-
}
549-
return first.version < second.version
543+
// unique and sorted all xcode versions
544+
allXcodeVersions.enumerated().filter { index, releasedVersion -> Bool in
545+
index == allXcodeVersions.firstIndex {
546+
releasedVersion.version == $0.version &&
547+
releasedVersion.version.isPrerelease == $0.version.isPrerelease &&
548+
releasedVersion.version.appleDescriptionWithBuildIdentifier == $0.version.appleDescriptionWithBuildIdentifier
550549
}
551-
.forEach { releasedVersion in
552-
var output = releasedVersion.version.appleDescriptionWithBuildIdentifier
553-
if installedXcodes.contains(where: { releasedVersion.version.isEquivalent(to: $0.version) }) {
554-
if releasedVersion.version == selectedInstalledXcodeVersion {
555-
output += " (\("Installed".blue), \("Selected".green))"
556-
}
557-
else {
558-
output += " (\("Installed".blue))"
550+
}.map{
551+
$0.element
552+
}.sorted { first, second -> Bool in
553+
554+
let predicates: [(ReleasedVersion, ReleasedVersion) -> Bool] = [
555+
{ $0.version < $1.version },
556+
{
557+
if let firstDate = $0.releaseDate, let secondDate = $1.releaseDate {
558+
return firstDate < secondDate
559+
} else {
560+
return false
559561
}
560562
}
561-
Current.logging.log(output)
563+
]
564+
565+
for predicate in predicates {
566+
if !predicate(first, second) && !predicate(second, first) {
567+
continue
568+
}
569+
return predicate(first, second)
570+
}
571+
572+
return false
573+
}.forEach { releasedVersion in
574+
var output = releasedVersion.version.appleDescriptionWithBuildIdentifier
575+
if installedXcodes.contains(where: { releasedVersion.version.isEquivalent(to: $0.version) }) {
576+
if releasedVersion.version == selectedInstalledXcodeVersion {
577+
output += " (\("Installed".blue), \("Selected".green))"
578+
}
579+
else {
580+
output += " (\("Installed".blue))"
581+
}
562582
}
583+
Current.logging.log(output)
584+
}
563585
}
564586
}
565587

0 commit comments

Comments
 (0)