Search code examples
iosswift4iqkeyboardmanager

How to fix Method 'initialize()' defines Objective-C class method 'initialize', which is not permitted by Swift in Swift 4?


I am updating my app from Swift 3 to Swift 4 and after migration, there are a few errors. One of them is Method 'initialize()' defines Objective-C class method 'initialize', which is not permitted by Swift in IQToolbar of IQKeyboardManager, how to fix this?


Solution

  • - You can also use Singleton solve this problem such as:

        static let shared : AudioTools = {
               $0.initialize()
               return $0
           }(AudioTools())
    

    Your Objective-C method--->initialize

    override class func initialize(){code here}
    

    change:

    func initialize(){code here}
    

    Your method here:

    func playSound(fileName:String?) {
           code here
        }
    

    use in Swift3:

    let audioPlayer = AudioTools.playMusic(fileName: fileName)
    

    use in Swift4

    let audioPlayer = AudioTools.shared.playMusic(fileName: fileName)