Current PHAssetResource From PHAssetResources

For any media content represented by PHAsset, the underlying file/files are represented by PHAssetResource. And to fetch the asset resources that represent the PHAsset

let resources = PHAssetResurce.assetResources(for: asset)

This provides you with an array of [PHAssetResource] object. And provides with a list of attributes like originalFilename, assetLocalIdentifier, type, and uniformTypeIdentifier. It is hard to figure out which one is the currently displayed file. Any processed photo, including a depth-image has the original image, and then a processed image (named FullSizeRender.jpg as much as I can observe).

The next pain point is, figuring out which of these PHAssetResource is getting used to represent the current resource that is being used. Here, the Photos framework does not provide any attribute to identify this. However, inspecting the PHAssetResource object on LLDB, you notice a key-value pair. isCurrent with a boolean value. This represents which PHAssetResource the system is currently using to represent the asset.

I have a small extension that helps me out here

extension PHAssetResource {
    var isCurrent: Bool? {
        self.value(forKey: "isCurrent") as? Bool
    }
}