---
title: "#33: Photos Framework Basics 🗻"
url: https://littlebitesofcocoa.com/33-photos-framework-basics
author: Jake Marsh
published: 2015-07-08
topics: ["Photos"]
description: "The Photos Framework is the modern equivalent to the old Assets Library Framework. It's how you access and interact with the user's photo library on iOS and..."
---

# #33: Photos Framework Basics 🗻

By Jake Marsh, July 8, 2015. HTML: https://littlebitesofcocoa.com/33-photos-framework-basics

The **Photos Framework** is the modern equivalent to the old **Assets Library Framework**. It's how you access and interact with the user's photo library on **iOS** and **OS X**. Here are a few examples of things you can do with it:

## Retrieve All Albums

``` swift
let fetchOptions = PHFetchOptions()

let albums = PHAssetCollection.fetchAssetCollectionsWithType(
  .Album,
  subtype: .Any,
  options: fetchOptions
)
```

## Mark a Photo As A Favorite

``` swift
PHPhotoLibrary.sharedPhotoLibrary().performChanges({
  let request = PHAssetChangeRequest(forAsset: photo)
  request.favorite = true
}, completionHandler: { (successful, error) in })
```

Changes must happen asynchronously when working with the Photos Framework so we use a PHAssetChangeRequest to mark a photo as a favorite.

## Retrieve an Image at Specific Size

``` swift
let manager = PHCachingImageManager()

manager.requestImageForAsset(asset,
  targetSize: CGSizeMake(50.0, 50.0),
  contentMode: PHImageContentMode.AspectFill,
  options: nil,
  resultHandler: {
    (image: UIImage?, userInfo: [NSObject : AnyObject]?) in
    // yay image!
  }
)
```

We didn't specify any options there, but you can use the `PHImageRequestOptions` to customize if you'd like to allow loading images over the network, as well as get a progress callback as they are downloaded.
