Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 8, PhotoKit, PHAsset, unique identifier

Tags:

ios

ios8

photokit

Working on an app that is iOS 8, and handles a lot of photos, I need to uniquely identify PHassets but cannot find any property to use? I found one property on

 PHObject/localIdentifier

documented here

https://developer.apple.com/library/ios/documentation/Photos/Reference/PHObject_Class/index.html#//apple_ref/occ/instp/PHObject/localIdentifier

Is there any way to have a unique ID on PHAsset? PHObject is a bit heavier to use.

like image 956
Huang Avatar asked Mar 02 '15 02:03

Huang


1 Answers

Yes, that's the only property to use.

However, PHObject implements both -hash and -isEqual: methods. It also conforms to NSCopying protocol, which means that it can be used as a key in dictionaries and can be put in sets, etc. It also continues to work when you reload PHAsset objects. This is a huge win over ALAsset class. The implementation of -isEqual is much faster than the localIdentifier property and can be safely used on the main thread. You could use profiler to get an idea of what's under the hood.

like image 52
kean Avatar answered Sep 19 '22 18:09

kean