2

After upgrading to Xcode 12 and Swift 5.3 my MLmodel no longer seems to work correctly I had no issues before. I'm sure it's a simple fix that I just don't understand how to fix.

let WpredictionModel = _14Win()

 func calculateWin() {
    guard let prediction = try? WpredictionModel.prediction(//all of my input data) else {
        fatalError("Unexpected runtime error.")
    }

I'm getting the error 'init()' is deprecated: Use init(configuration:) instead and handle errors appropriately. after the WpredictionModel declaration.

I'm also getting this as an error.

 @available(macOS 11.0, iOS 14.0, tvOS 14.0, watchOS 7.0, *)
    class func load(contentsOf modelURL: URL, configuration: MLModelConfiguration = MLModelConfiguration(), completionHandler handler: @escaping (Swift.Result<_14Win, Error>) -> Void) {
        MLModel.__loadContents(of: modelURL, configuration: configuration) { (model, error) in
            if let error = error {
                handler(.failure(error))
            } else if let model = model {
                handler(.success(_14Win(model: model)))
            } else {
                fatalError("SPI failure: -[MLModel loadContentsOfURL:configuration::completionHandler:] vends nil for both model and error.")
            }
        }
    }
kris63
  • 31
  • 2

1 Answers1

0

Kris. I have the same problem after Xcode12 update yesterday!

Xcode automatically generates the following code from my mlmodel file. But the 'MLModel' DO NOT have 'loadContentsOfURL...'. The automatically-generated file is not editable, I can do nothing...

    + (void)loadContentsOfURL:(NSURL *)modelURL configuration:(MLModelConfiguration *)configuration completionHandler:(void (^)(AIASCore * _Nullable model, NSError * _Nullable error))handler {
    [MLModel loadContentsOfURL:modelURL
                 configuration:configuration
             completionHandler:^(MLModel *model, NSError *error) {
        if (model != nil) {
            AIASCore *typedModel = [[AIASCore alloc] initWithMLModel:model];
            handler(typedModel, nil);
        } else {
            handler(nil, error);
        }
    }];
}
Kishan Bharda
  • 5,446
  • 3
  • 30
  • 57