Class

PHAsset

A representation of an image, video, or Live Photo in the Photos library.

Declaration

class PHAsset : PHObject

Overview

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.

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. Iff 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 PHImageManager.

Asset objects are immutable. To edit an asset’s metadata (such as marking it as a favorite photo), create a PHAssetChangeRequest object within a photo library change block. For more details on using change requests and change blocks to update the photo library, see PHPhotoLibrary.

Topics

Fetching Assets

Fetching Assets

Retrieve asset metadata or request full asset content.

class func fetchAssets(withLocalIdentifiers: [String], options: PHFetchOptions?) -> PHFetchResult<PHAsset>

Retrieves assets with the specified local-device-specific unique identifiers.

class func fetchKeyAssets(in: PHAssetCollection, options: PHFetchOptions?) -> PHFetchResult<PHAsset>?

Retrieves assets marked as key assets in the specified asset collection.

class func fetchAssets(with: PHFetchOptions?) -> PHFetchResult<PHAsset>

Retrieves all assets matching the specified options.

class func fetchAssets(withALAssetURLs: [URL], options: PHFetchOptions?) -> PHFetchResult<PHAsset>

Retrieves assets using URLs provided by the Assets Library framework.

Deprecated

Reading Asset Metadata

var mediaType: PHAssetMediaType

The type of the asset, such as video or audio.

enum PHAssetMediaType

Constants identifying the general type of an asset, such as image or video.

var mediaSubtypes: PHAssetMediaSubtype

The subtypes of the asset, identifying special kinds of assets such as panoramic photo or high-framerate video.

struct PHAssetMediaSubtype

Constants identifying specific variations of asset media, such as panorama or screenshot photos and time lapse or high frame rate video.

var sourceType: PHAssetSourceType

The means by which the asset entered the user’s Photos library.

struct PHAssetSourceType

Means by which an asset enters the Photos library, used by the PHAssetSourceType property.

var pixelWidth: Int

The width, in pixels, of the asset’s image or video data.

var pixelHeight: Int

The height, in pixels, of the asset’s image or video data.

var creationDate: Date?

The date and time at which the asset was originally created.

var modificationDate: Date?

The date and time at which the asset was last modified.

var location: CLLocation?

The location information saved with the asset.

var duration: TimeInterval

The duration, in seconds, of the video asset.

var isFavorite: Bool

A Boolean value that indicates whether the user has marked the asset as a favorite.

var isHidden: Bool

A Boolean value that indicates whether the user has hidden the asset.

var isSyncFailureHidden: Bool

A Boolean value that indicates whether the user has chosen to hide to the sync failure message.

Displaying an Asset

var playbackStyle: PHAsset.PlaybackStyle

An enumerated value that describes how to present an asset to the user.

enum PHAsset.PlaybackStyle

An enumeration of asset playback styles that dictate how to present an asset to the user.

Editing an Asset

Editing Asset Content

Make a request to modify and save a photo or video asset.

class PHContentEditingInput

A container that provides information about and access to the image, video, or Live Photo content of an asset to be edited.

class PHContentEditingOutput

A container to which you provide the results of editing the photo, video, or Live Photo content of a Photos asset.

class PHAdjustmentData

A description of the edits made to an asset's photo, video, or Live Photo content, which allows your app to reconstruct or revert the effects of prior editing sessions.

class PHContentEditingInputRequestOptions

A set of options affecting the delivery of image or video data when you request to edit the content of a Photos asset.

class PHLivePhotoEditingContext

An editing session for modifying the photo, video, and audio content of a Live Photo.

protocol PHLivePhotoFrame

A container that provides image content for a single frame of a Live Photo in an editing context.

func canPerform(PHAssetEditOperation) -> Bool

Returns whether the asset supports the specified editing operation.

enum PHAssetEditOperation

Values identifying possible actions an asset can support, used by the canPerform(_:) method.

func cancelContentEditingInputRequest(PHContentEditingInputRequestID)

Cancels a request for editing the asset’s content.

typealias PHContentEditingInputRequestID

An identifier for an asset content editing session.

Editing Request Info Keys

Keys indicating the status of an asset content editing request, used in the completion handler of the requestContentEditingInput(with:completionHandler:) method.

Working with Burst Photo Assets

var burstIdentifier: String?

The unique identifier shared by photo assets from the same burst sequence.

var burstSelectionTypes: PHAssetBurstSelectionType

The selection type of the asset in a burst photo sequence.

struct PHAssetBurstSelectionType

Bit mask values indicating whether and how an asset is marked as a favorite member of a burst photo sequence. Used by the burstSelectionTypes property.

var representsBurst: Bool

A Boolean value that indicates whether the asset is the representative photo from a burst photo sequence.

Relationships

Inherits From

Conforms To

See Also

Asset Retrieval

Fetching Objects and Requesting Changes

Get assets, asset collections, and collection lists matching a specified query.

class PHAssetCollection

A representation of a Photos asset grouping, such as a moment, user-created album, or smart album.

class PHCollection

The abstract superclass for Photos asset collections and collection lists.

class PHCollectionList

A group containing Photos asset collections, such as Moments, Years, or folders of user-created albums.

class PHObject

The abstract superclass for Photos model objects (assets and collections).

class PHFetchResult

An ordered list of assets or collections returned from a Photos fetch method.

class PHFetchOptions

A set of options that affect the filtering, sorting, and management of results that Photos returns when you fetch asset or collection objects.