Contents

loadValuesAsynchronously(forKeys:completionHandler:)

Tells the asset to load the values of all of the specified keys that aren’t already loaded.

Declaration

func loadValuesAsynchronously(forKeys keys: [String], completionHandler handler: (@Sendable () -> Void)? = nil)
func loadValues(forKeys keys: [String]) async

Parameters

  • keys:

    An array of strings containing the keys to load. The keys are the property names of a class that adopts the protocol.

  • handler:

    The closure the system calls when the load request completes.

Mentioned in

Discussion

Regardless of the number of keys specified, the system calls the completion handler only once per invocation of this method. The system calls this method:

  • Synchronously if the asset already loaded the specified keys, or if an I/O error or other format-related error occurs immediately.

  • Asynchronously when the values of the specified keys become loaded, if a loading error occurs at a later stage of processing, or you cancel loading. The system calls the closure on a background queue, so you should dispatch control back to the main queue before performing any user interface-related operations.

The completion states of the specified keys aren’t necessarily the same—some may return loaded, and others may have failed. Check the status of each key individually using the statusOfValue(forKey:error:) method.

The following example shows how to use this method to load an asset’s isPlayable key:

// Load the asset's "commonMetadata" key
[asset loadValuesAsynchronouslyForKeys:@[@"commonMetadata"] completionHandler:^{
    NSError *error = nil;
    AVKeyValueStatus status =
        [asset statusOfValueForKey:@"commonMetadata" error:&error];
    switch (status) {
        case AVKeyValueStatusLoaded:
            // The property successfully loaded. Continue processing.
             break;
        case AVKeyValueStatusFailed:
            // Examine the NSError pointer to determine the failure.
            break;
        case AVKeyValueStatusCancelled:
            // The asset canceled loading.
            break;
        default:
            // Handle all other cases.
            break;
    }
}];

See Also

Deprecated