Contents

loadContentsOfURL:configuration:completionHandler:

Creates a Core ML model instance asynchronously from a compiled model file, a custom configuration, and a completion handler.

Declaration

+ (void) loadContentsOfURL:(NSURL *) url configuration:(MLModelConfiguration *) configuration completionHandler:(void (^)(MLModel *model, NSError *error)) handler;

Parameters

  • url:

    The path to a compiled model file (ModelName.mlmodelc), typically with the URL that Compilemodel(at:) 6442s returns.

  • configuration:

    The runtime settings for the new model instance.

  • handler:

    A closure the method calls when it finishes loading the model.

Mentioned in

Discussion

Use this method to load a model asynchronously. Core ML calls your completion handler after it successfully loads the model, or encounters an error attempting to load it.

In Swift, if the model loaded successfully, you can use the instance from the Result.success(_:) associated value; otherwise, use the Result.failure(_:) associated value to address the error. In Objective-C, you can use the MLModel instance in your completion hander; otherwise, use the NSError instance to address the error. See MLModelError.Code for the list of error codes.