I have code that stopped working when I switched from Swift 3.2 to Swift 4.0. It's goal is to add click action to all UIButtons and UISwitches.
private func turnSound(state: Bool) {
UIButton.appearance().isSoundEnabled = state
UISwitch.appearance().isSoundEnabled = state
}
extension UIControl {
var isSoundEnabled: Bool {
get {
return target(forAction: #selector(AudioManager.playStandardClickSound), withSender: nil) != nil ? true : false
}
set {
if newValue {
addTarget(AudioManager.manager, action: #selector(AudioManager.playStandardClickSound), for: .touchUpInside)
} else {
removeTarget(AudioManager.manager, action: #selector(AudioManager.playStandardClickSound), for: .touchUpInside)
}
}
}
}
It worked well before, but now I'm getting an exception:
'NSInvalidArgumentException', reason: '*** Illegal axis type, : for appearance setter, addTarget:action:forControlEvents:. Expected NSInteger or NSUInteger'
And I don't understand how to get rid of this problem.
Will be glad to any help or alternative solution.
UPDATE: