Parses AppVersion.minOSVersion/maxOSVersion from source JSON

Uses them to implement AppVersion.isSupported.
This commit is contained in:
Riley Testut
2022-11-15 16:30:17 -06:00
parent 8609209821
commit 701065b073

View File

@@ -54,6 +54,8 @@ public class AppVersion: NSManagedObject, Decodable, Fetchable
case localizedDescription
case downloadURL
case size
case minOSVersion
case maxOSVersion
}
public required init(from decoder: Decoder) throws
@@ -72,6 +74,9 @@ public class AppVersion: NSManagedObject, Decodable, Fetchable
self.downloadURL = try container.decode(URL.self, forKey: .downloadURL)
self.size = try container.decode(Int64.self, forKey: .size)
self._minOSVersion = try container.decodeIfPresent(String.self, forKey: .minOSVersion)
self._maxOSVersion = try container.decodeIfPresent(String.self, forKey: .maxOSVersion)
}
catch
{
@@ -115,6 +120,15 @@ public extension AppVersion
}
var isSupported: Bool {
if let minOSVersion = self.minOSVersion, !ProcessInfo.processInfo.isOperatingSystemAtLeast(minOSVersion)
{
return false
}
else if let maxOSVersion = self.maxOSVersion, ProcessInfo.processInfo.operatingSystemVersion > maxOSVersion
{
return false
}
return true
}
}