Photo Assets and PHAsset Class

Photos and videos are, at their base level, model objects. Think back to our old friend, the Model-View-Controller, introduced back in Model-View-Controller. A well-designed model object should be a reusable piece of information that can be accessed from many different controller objects without any dependencies tying it to one specific application or project.

Model objects contain data, and they provide access to and implement logic on data. Photos and videos are just sets of data that we store on our phone that can be accessed and modified by many different applications. Our photo model objects are also read-only and thread-safe, so no worrying about another application coming in and changing our photos out from under us.

Every photo and video we use is also considered an asset. Individual assets belong to collections. These are the building blocks of how our photographs are organized; it’s important to remember this structure when working with PhotoKit.

The PHAsset class is the foundation of everything we will be doing this chapter. PHAsset encompasses not just photos but videos as well. This class stores the asset’s media type, creation date, location, and whether it has been tagged as a favorite. All of these properties give you a tremendous amount of control over filtering out which specific photos you would like to use.

For example, say you take a family vacation to Disney World every year. You want to find a specific picture in your photo library, but you aren’t sure which trip it was that you took the picture on. You can filter the photos by location and whether they’re tagged as a favorite to narrow down which photo it might be. If you know which trip it was on, you can filter them down further by creation date.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.207.70