19 August 2015 1min read

Photos framework with ReactiveCocoa

In the last version of BWallpapers I added the ability to save the wallpaper to a specific Wallpaper album in the Photos app.

You can use the Photos.framework to do that. I found that the framework is a little different from what you can find in any other iOS framework. It uses a lot of async APIs and immutability.

For example to make any change you have to build a change request and then perform the request, all in a performChanges async block.

I just had a very limited use case: saving an image to a specific album. But even with that simple case the async API was starting to make my code really ugly.

  • Check for authorization to access the Photos
  • Check if the Album already exists
  • If not, create the Album (and fetch it)
  • Save the image

As you can see is not a lot of work, but it’s easy to end up with a callback hell. So I made a little wrapper around Photos.framework using ReactiveCocoa 3.

I wanted to simplify my code in a way that I just have to declare the operations that I want to do without thinking on how to do the operations.

You can check RACPhotos in Github! It only includes this basic operations, because is all I needed. I recommend everyone exploring the making of this small wrappers to make some async APIs a lot easier with some FRP framework.

And thanks to Javi for the help via Twitter ^^

If you enjoyed this post

Continue reading