Getting 'init()' is deprecated: Use init(configuration:) instead and handle errors appropriately.

I am trying to make an Image Classifier but I keep getting a warning 'init()' is deprecated: Use init(configuration:) instead and handle errors appropriately. I was wondering if it matters because the app gets made and the classifier works. Just wondering what the warning means.

Thanks in advance!

Accepted Reply

This is simply a deprecation warning saying that the method you are using to initialize the CoreML model will not be supported in the future. I would suggest updating your code to use the more recent initialization technique as follows.

let model: ImageClassifierModel = try! ImageClassifierModel(configuration: .init())

or

let model: ImageClassifierModel = try! ImageClassifierModel(configuration: MLModelConfiguration())

Although, I would also handle the error if the model fails to initialize.

Add a Comment

Replies

This is simply a deprecation warning saying that the method you are using to initialize the CoreML model will not be supported in the future. I would suggest updating your code to use the more recent initialization technique as follows.

let model: ImageClassifierModel = try! ImageClassifierModel(configuration: .init())

or

let model: ImageClassifierModel = try! ImageClassifierModel(configuration: MLModelConfiguration())

Although, I would also handle the error if the model fails to initialize.

Add a Comment