diff --git a/DevCleaner/Model/Entries/DeviceSupportFileEntry.swift b/DevCleaner/Model/Entries/DeviceSupportFileEntry.swift index dcb85d1..ea3922c 100644 --- a/DevCleaner/Model/Entries/DeviceSupportFileEntry.swift +++ b/DevCleaner/Model/Entries/DeviceSupportFileEntry.swift @@ -60,12 +60,12 @@ public final class DeviceSupportFileEntry: XcodeFileEntry { public let device: String? public let osType: OSType public let version: Version - public let build: String? + public let build: AppleBuild? public let date: Date public let architecture: String? // MARK: Initialization - public init(device: String?, osType: OSType, version: Version, build: String?, date: Date, arch: String?, selected: Bool) { + public init(device: String?, osType: OSType, version: Version, build: AppleBuild?, date: Date, arch: String?, selected: Bool) { self.device = device self.osType = osType self.version = version @@ -73,7 +73,7 @@ public final class DeviceSupportFileEntry: XcodeFileEntry { self.date = date self.architecture = arch - let label = "\(self.osType.description) \(self.version) \(self.build ?? "")" + let label = "\(self.osType.description) \(self.version) \(self.build ?? AppleBuild.empty)" let tooltip = label + " " + DateFormatter.localizedString(from: self.date, dateStyle: .medium, timeStyle: .none) super.init(label: label, tooltipText: tooltip, icon: DeviceSupportFileEntry.icon(for: osType, version: version), tooltip: true, selected: selected) diff --git a/DevCleaner/Model/XcodeFiles.swift b/DevCleaner/Model/XcodeFiles.swift index 0e8e3d6..7d1fde6 100644 --- a/DevCleaner/Model/XcodeFiles.swift +++ b/DevCleaner/Model/XcodeFiles.swift @@ -198,7 +198,7 @@ final public class XcodeFiles { let device: String? let version: Version - let build: String? + let buildString: String? let creationDate: Date = FileManager.default.dateCreated(for: url) let arch: String? @@ -208,14 +208,14 @@ final public class XcodeFiles { version = foundVersion if splitted.count > 1 { - build = String(splitted[1]) + buildString = String(splitted[1]) if splitted.count > 2 { arch = String(splitted[2]) } else { arch = nil } } else { - build = nil + buildString = nil arch = nil } } else if splitted.count > 1, let foundVersion = Version(describing: String(splitted[1])) { // if version is second, we may have extra device info @@ -223,14 +223,14 @@ final public class XcodeFiles { version = foundVersion if splitted.count > 2 { - build = String(splitted[2]) + buildString = String(splitted[2]) if splitted.count > 3 { arch = String(splitted[3]) } else { arch = nil } } else { - build = nil + buildString = nil arch = nil } } else { @@ -241,7 +241,7 @@ final public class XcodeFiles { return DeviceSupportFileEntry(device: device, osType: DeviceSupportFileEntry.OSType(label: osLabel), version: version, - build: build, + build: (buildString != nil) ? AppleBuild(string: buildString!) : nil, date: creationDate, arch: arch, selected: true) @@ -470,7 +470,14 @@ final public class XcodeFiles { // sort deviceSupportEntries = deviceSupportEntries.sorted { (lhs, rhs) -> Bool in - lhs.version > rhs.version + if lhs.version == rhs.version { + let lhsBuild = lhs.build ?? AppleBuild.empty + let rhsBuild = rhs.build ?? AppleBuild.empty + + return lhsBuild > rhsBuild + } else { + return lhs.version > rhs.version + } } // merge (in case we have different architectures) diff --git a/DevCleaner/Utilities/Version.swift b/DevCleaner/Utilities/Version.swift index 6418e61..5e0114f 100644 --- a/DevCleaner/Utilities/Version.swift +++ b/DevCleaner/Utilities/Version.swift @@ -27,15 +27,6 @@ public struct Version { public let minor: UInt public let patch: UInt? - public var description: String { - var result = "\(self.major).\(self.minor)" - if let patch = self.patch { - result += ".\(patch)" - } - - return result - } - // MARK: Initialization init(major: UInt, minor: UInt, patch: UInt? = nil) { self.major = major @@ -85,7 +76,7 @@ public struct Version { } } -// MARK: Comparable implementation +// MARK: - Comparable implementation extension Version: Comparable { public static func ==(lhs: Version, rhs: Version) -> Bool { if lhs.major == rhs.major { @@ -118,8 +109,15 @@ extension Version: Comparable { } } -// MARK: CustomStringConvertible conformance +// MARK: - CustomStringConvertible conformance extension Version: CustomStringConvertible { - + public var description: String { + var result = "\(self.major).\(self.minor)" + if let patch = self.patch { + result += ".\(patch)" + } + + return result + } }