Apple’s Photos.framework, which powers the iOS Photos and gives developers access to the device’s photo library, uses Core Data under the hood.

You can confirm this in at least two places:

  1. Write an app that accesses the photo library and launch it with these command line arguments: 1. As you access the photo library, you’ll see Core logging debug information to the Console.

  2. If you look at a class dump of the Photos framework, you’ll see references to NSManagedObjectID and other Core Data types in the main classes, e.g. PHObject has an _objectID: NSManagedObjectID ivar.

In my quest to understand the Photos framework better (especially its performance characteristics), I wanted to inspect its data . I found a file named PhotoLibraryServices.framework/photos.momd/ deep in the bowels of the Xcode 10.0 app bundle:


A .mom file is a compiled Core Data model. Xcode can’t open this directly, but it can import one into another Core Data model. Follow these steps to view the model in Xcode:

  1. Create a new empty project. Xcode 10 doesn’t like to display Core Data model bundles outside of a project.
  2. Create a new empty “Core Data Data Model” file inside the project. This will create an .xcdatamodeld bundle.
  3. Open the new data model and select Editor > Import…. Select the .mom file you want to import.

Unfortunately, the compiled model doesn’t store the layout information for Xcode’s graphical model editor, so you’ll have to manually drag the entities into a pleasing layout. This took me a few hours.

This is as bundled with Xcode 10.0 (iOS .0):

Visual overview of the Core Data data model of the Photos.framework in iOS 12.0  - photos 10 - PhotoKit’s data model – Ole Begemann
The Core Data data model of the PhotoLibraryServices.framework in iOS 12.0. Click the image for a high-resolution version.

Not everything can be seen in this image. Download the full model and open it in Xcode to inspect attribute properties etc.

Note that this isn’t necessarily the entire data model for photos on iOS. There are more Core Data models in PrivateFrameworks/PhotoAnalysis.framework which I ignored.

Source link
Based Blockchain


Please enter your comment!
Please enter your name here