Makes the SizeType initializer prefer proper case but fall back to case insensitive.

This commit is contained in:
2021-03-25 01:21:45 -07:00
parent cd559abbb0
commit 9fd4c1f71d

View File

@@ -27,4 +27,26 @@ enum SizeType: String, CaseIterable, Identifiable {
case .gargantuan: return "gargantuan" case .gargantuan: return "gargantuan"
} }
} }
init?(rawValue: String) {
var match: SizeType? = nil
for size in SizeType.allCases {
if (size.rawValue == rawValue) {
match = size
}
}
for size in SizeType.allCases {
if (size.rawValue.lowercased() == rawValue.lowercased()) {
match = size
}
}
if (match == nil) {
return nil
} else {
self = match!
}
}
} }