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 2e46676ecd
commit 89376e85a1

View File

@@ -27,4 +27,26 @@ enum SizeType: String, CaseIterable, Identifiable {
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!
}
}
}