Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 948
Varun Naharia Avatar asked Jun 12 '17 08:06

Varun Naharia


1 Answers

- 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) 
like image 171
user8152635 Avatar answered Oct 04 '22 04:10

user8152635