I was using the UIUserNotificationType.none
in Swift3 on ViewController.swift, and I got this error: 'none' is unavailable user[] to construct an empty option set ; Here is my code:
func updateUI() {
let currentSettings = UIApplication.shared.currentUserNotificationSettings
if currentSettings?.types != nil {
if currentSettings!.types == [UIUserNotificationType.badge, UIUserNotificationType.alert] {
textField.isHidden = false
button.isHidden = false
datePicker.isHidden = false
}
else if currentSettings!.types == UIUserNotificationType.badge {
textField.isHidden = true
}
else if currentSettings!.types == UIUserNotificationType.none {
textField.isHidden = true
button.isHidden = true
datePicker.isHidden = true
}
}
}
As the error says, there is no .none
member to that OptionSet
type. Just use []
, the empty option set.
This should work:
func updateUI() {
guard let types = UIApplication.shared.currentUserNotificationSettings?.types else {
return
}
if types == [.badge, .alert] {
textField.isHidden = false
button.isHidden = false
datePicker.isHidden = false
}
else if types == [.badge] {
textField.isHidden = true
}
else if types.isEmpty {
textField.isHidden = true
button.isHidden = true
datePicker.isHidden = true
}
}
Even better, use a switch:
func updateUI() {
guard let types = UIApplication.shared.currentUserNotificationSettings?.types else {
return
}
switch types {
case [.badge, .alert]:
textField.isHidden = false
button.isHidden = false
datePicker.isHidden = false
case [.badge]:
textField.isHidden = true
case []:
textField.isHidden = true
button.isHidden = true
datePicker.isHidden = true
default:
fatalError("Handle the default case") //TODO
}
}
So replace every instance of UIUserNotificationType.none
with []
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With