2017-10-18 8 views
0

Swift 3.2からSwift 4.0に切り替えたときに動作しなくなったコードがあります。それはすべてのUIButtonsとUISwitchにクリックアクションを追加することです。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:

答えて

1

あなたも、あなたの内線に@objcを追加する必要があります。

@objc extension UIControl 

P.S.クレジットはこの回答に行くhttps://stackoverflow.com/a/44391389/2241008

+0

それです。どうもありがとう! –

関連する問題