30

PhotoKit 的数据模型

 4 years ago
source link: https://www.tuicool.com/articles/U7VFBnY
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

作者:Ole Begemann, 原文链接 ,原文日期:2018-09-28

译者: 张弛 ;校对: numbbbbbYousanflics ;定稿: Forelax

在 iOS 系统中, PhotoKit 框架 不仅被系统的照片 App 所使用,同时它也为开发人员访问设备的照片库提供了接口支持。而它的底层则是 Core Data 实现的。

至少从这两个地方,你就可以确认这一点:

  1. 编写一个能够访问照片库的应用,并使用 -com.apple.CoreData.SQLDebug 1. 来启动这个应用程序。当你访问照片库时,从控制台就可以看到 Core Data 的调试信息。
  2. 如果查看 PhotoKit 框架的 class dump ,你将会在主要的类中看到对 NSManagedObjectID 和其他 Core Data 类型的引用,例如, PHObject 有一个 _objectID:NSManagedObjectID 的 ivar

寻找 PhotoKit 的核心数据模型

为了更好地理解 PhotoKit 框架(特别是它的性能特征),我检查了它的数据模型。我在 Xcode 10.0 应用程序的包内容中找到了一个名为 PhotoLibraryServices.framework / photos.momd / photos-10.0.mom 的文件:

/Applications/Xcode-10.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/PhotoLibraryServices.framework/photos.momd/photos-10.0.mom

你可以使用如下的命令来查找 Xcode 中模拟器运行时内的其他 Core Data 模型:

find /Applications/Xcode-10.app -name '*.mom'

在 Xcode 中打开已编译的 Core Data 模型

.mom 文件是 已编译的 Core Data 数据模型。Xcode 无法直接打开它,但可以将它 导入 到另一个 Core Data 模型中。通过如下的步骤,我们就可以在 Xcode 中查看这个模型:

.xcdatamodeld
.mom

不幸的是,编译的模型并不存储 Xcode 的模型编辑器的布局信息,因此你必须手动将编辑器中的实体拖出来一个漂亮的样式中。这花了我几个小时。

温馨提示:你可以使用箭头键(和 shift 键+箭头键)精确定位事物。

专家提示:请勿点击 ⌘Z 撤消移动操作。对图形的编辑不会被 Xcode 视作一个可撤销的操作,因此 Xcode 可能会撤消一开始的导入操作,这意味着你将丢失所有未保存的工作。

带有良好格式的 PhotoKit 的模型

这是与 Xcode 10.0(iOS 12.0)捆绑在一起的 photos-10.0.mom

photos-10.0-core-data-model-5974px.png

并非所有的内容都能在这张图片中被看到。你可以 下载完整模型 并在 Xcode 中查看它的一些属性。

请注意,这不一定是 iOS 上的照片的完整数据模型。更多的一些 Core Data 模型被放置在 PrivateFrameworks/PhotoAnalysis.framework 中。

本文由 SwiftGG 翻译组翻译,已经获得作者翻译授权,最新文章请访问http://swift.gg。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK