Trying to determine if an input string is a valid phone number using CharacterSet
. Seems that isSubset
works fine, but isSuperset
will crash.
I think this is a bug in Foundation.
let phoneNumberCharacterSet = CharacterSet(charactersIn: "01234567890,;*+#").union(CharacterSet.whitespaces)
let zeroCharacterSet = CharacterSet(charactersIn: "0")
if zeroCharacterSet.isSubset(of: phoneNumberCharacterSet) {
print("zero is a subset of the phone number set")
}
if phoneNumberCharacterSet.isSuperset(of: zeroCharacterSet) {
// will never get here due to crash
print("is a superset of '0'")
}