PHAsset
Also known as: phasset ios, photo asset api
PHAsset is the PhotoKit object that represents a single photo, video, or Live Photo in the iOS Photos library. It carries metadata such as capture date, dimensions, and media type, but holds no pixel data itself; the actual image is loaded on demand through PHImageManager using the asset's identifier.
- A PHAsset stores metadata only, never the underlying photo or video bytes.
- Its localIdentifier is a stable string used to reference an asset across launches.
- PHAssets are immutable; edits and deletions go through PHPhotoLibrary change requests.
What a PHAsset represents
A PHAsset is a lightweight, immutable descriptor for one item in the Photos library: a still image, a video, or a Live Photo. It is identified by a stable localIdentifier string that survives app launches, which is what cleanup tools store to remember a selection.
The object exposes metadata only: `mediaType` and `mediaSubtypes` (e.g. Live Photo, HDR, screenshot), `pixelWidth` and `pixelHeight`, `creationDate`, `location`, `isFavorite`, and `duration` for videos. The real bytes live elsewhere and are never attached to the asset directly.
Fetching and loading data
Apps obtain assets by running a PHFetchRequest against PHAsset, optionally filtered by media type or sorted by creation date, which returns a PHFetchResult that loads its members lazily. To display or analyze pixels, the app passes the asset to PHImageManager, which returns a thumbnail or full image asynchronously and may deliver a degraded placeholder first.
Because metadata is cheap and pixels are expensive, scanning a large library for duplicate or similar photos starts by reading PHAsset fields and small thumbnails, only fetching full resolution when truly needed.
Editing and deleting
A PHAsset is immutable, so changes never happen on the object directly. To delete or modify assets, the app wraps a `PHAssetChangeRequest` inside a performChanges block on PHPhotoLibrary; deletion routes the items to Recently Deleted and prompts a system confirmation.
For Cleanor, the PHAsset is the unit of comparison: its capture date, dimensions, and content hash drive duplicate detection, and its localIdentifier is the handle used to batch-delete the items a user chooses to remove.