Contents

execute(_:with:)

Returns a value as appropriate for the given request, or nil if the request cannot be completed.

Declaration

func execute(_ request: NSPersistentStoreRequest, with context: NSManagedObjectContext?) throws -> Any

Parameters

  • request:

    A fetch request.

  • context:

    The managed object context used to execute request.

Return Value

A value as appropriate for request, or nil if the request cannot be completed

Discussion

The value to return depends on the result type (see resultType) of request:

  • If it is NSManagedObjectResultType, NSManagedObjectIDResultType, or NSDictionaryResultType, the method should return an array containing all objects in the store matching the request.

  • If it is NSCountResultType, the method should return an array containing an NSNumber whose value is the count of all objects in the store matching the request.

  • If the request is a save request, the method should return an empty array.

If the save request contains nil values for the inserted/updated/deleted/locked collections; you should treat it as a request to save the store metadata.

You should implement this method conservatively, and expect that unknown request types may at some point be passed to the method. The correct behavior in these cases is to return nil and an error.

See Also

Manipulating Managed Objects