2017-10-18 84 views
0

我有從Swift 3.2切換到Swift 4.0時停止工作的代碼。它的目標是向所有UIButtons和UISwitches添加點擊操作。UIControl.appearance()。addTarget在Swift上停止工作4

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) 
      } 
     } 
    } 
} 

它也工作過,但現在我得到一個異常:

'NSInvalidArgumentException', reason: '*** Illegal axis type, : for appearance setter, addTarget:action:forControlEvents:. Expected NSInteger or NSUInteger' 

而且我不知道如何擺脫這個問題。

很高興有任何幫助或替代解決方案。

UPDATE:

回答