A representation of an image, video or Live Photo in the Photos library.
- iOS 8.0+
- macOS 10.13+
- tvOS 10.0+
You fetch assets to begin working with them. Use the class methods listed in Fetching Assets to retrieve one or more
PHAsset instances representing the assets you want to display or edit. For example, to fetch all the assets in an asset collection (such as an album or moment), use the
fetch method. Each fetch method takes a
PHFetch parameter that you can use to specify which assets you want to retrieve and how to sort them.
Assets contain only metadata. The underlying image or video data for any given asset might not be stored on the local device. However, depending on how you plan to use this data, you may not need to download all of it. For example, if you need to populate a collection view with thumbnail images, the Photos framework can manage downloading, generating, and caching thumbnails for each asset. For details, see
Asset objects are immutable. To edit an asset’s metadata (for example, to mark it as a favorite photo), create a
PHAsset object within a photo library change block. For more details on using change requests and change blocks to update the photo library, see
Asset Versions and Editing Asset Content
For each photo asset, Photos keeps a previous and a current version of its image data, as well as a
PHAdjustment object that describes the last edit the user made to each asset’s content. Your app uses this information to support resumable editing.
When you begin editing an asset, Photos first asks whether your app can interpret the adjustment data from the most recent edit. If so, Photos provides the previous version of the asset as input for your editing session. After you read the adjustment data and reconstruct the edit it describes, your app might let the user alter or revert the last edit or make further changes. (For example, adjustment data may describe filters applied to a photo. Your app reapplies those filters and allows the user to change filter parameters, add new filters, or remove filters.)
If your app does not support an asset’s adjustment data, Photos provides the current version of the asset as input to your editing session. The current version contains the rendered output of all past edits, so your app can further edit the asset but cannot alter or revert most recent edit.
For video assets, Photos does not store a previous version. If your app cannot read a video asset’s adjustment data, you must work with the current version of the video and future edits cannot make use of your app’s adjustment data.
To edit a
PHAsset object’s photo or video content:
Call the asset’s
Content Editing Input(with: completion Handler:)
PHContentobject you provide for the
Editing Input Request Options
optionsparameter controls whether your app can handle the asset’s adjustment data.
Photos calls your
completionblock, providing a
PHContentobject you can use for retrieving the image or video data to be edited.
Apply your edits to the asset. To allow a user to continue working with your edits later, create a new
PHAdjustmentobject describing the changes.
PHContentobject. For photo- or video-only assets, use the editing output’s properties to provide edited asset data. For Live Photo assets, create a
PHLiveobject to edit the Live Photo content.
Photo Editing Context
Commit your edits to the photo library by posting a change block to the shared
PHPhotoobject. In the block, create a
PHAssetobject and set its
contentproperty to the editing output that you created.
performcall prompts the user for permission to edit the contents of the photo library—to edit multiple assets in one batch, create multiple
PHAssetobjects within the same change block, each with its own corresponding