Reputation: 993
Can you help me to convert these if
statements into a switch
with cases please?
I'm struggling for a while and I can't figure out how to make it work.
Here is the code:
class Settings: NSObject {
let name: SettingsName
let imageName: String
init(name: SettingsName, imageName: String){
self.name = name
self.imageName = imageName
}
}
enum SettingsName: String {
case settings = "Settings"
case terms = "Terms & privacy policy"
case feedback = "Send Feedback"
case help = "Help"
case switchAccount = "Switch Account"
case cancel = "Cancel"
}
@objc func handleDismiss(setting: Settings) {
UIView.animate(withDuration: 0.5, animations: {
self.blackView.alpha = 0
if let window = UIApplication.shared.keyWindow {
self.collectionView.frame = CGRect(x: 0, y: window.frame.height, width: self.collectionView.frame.width, height: self.collectionView.frame.height)
}
}, completion: { (_) in
if setting.name == .settings {
self.homeController?.showControllerForAccountSettings(setting: setting)
}
if setting.name == .terms {
self.homeController?.showControllerForTermsAndPrivacy(setting: setting)
}
else if setting.name != .cancel && setting.name != .settings{
self.homeController?.showDummyControllerForSetting(setting: setting)
}
})
}
Upvotes: 0
Views: 84
Reputation: 130072
It seems like you want to do this:
switch settings.name {
case .settings:
self.homeController?.showControllerForAccountSettings(setting: setting)
case .terms:
self.homeController?.showControllerForTermsAndPrivacy(setting: setting)
case .cancel:
break
default:
self.homeController?.showDummyControllerForSetting(setting: setting)
}
Upvotes: 3