简体   繁体   English

将 CMTime 保存在核心数据 + Xcode8 + swift3

[英]save CMTime in core data + Xcode8 + swift3

I declared two attributes ( currentTime and fullTime ) as Transformable in data model as shown below.我在数据模型中声明了两个属性( currentTimefullTime )为Transformable ,如下所示。

在此处输入图片说明

How to save data in this attribute?如何在这个属性中保存数据? Do I need to convert to NSData first?我需要先转换为NSData吗? or any other way?或任何其他方式?

Transformable need to be convertible to NSData . Transformable 需要可转换为NSData When you're using a type that conforms to the NSCoding protocol, that happens automatically.当您使用符合NSCoding协议的类型时,这会自动发生。 When you're not (as with CMTime ), you can't use a transformable unless you create your own custom transformer by subclassing NSValueTransformer .当您不是时(与CMTime ),除非您通过子类化NSValueTransformer创建自己的自定义转换器,否则不能使用可转换。

You may find it easier to simply save the CMTime properties in Core Data and reconstruct the CMTime from those.您可能会发现简单地将CMTime属性保存在 Core Data 中并CMTime重建CMTime更容易。 The properties are all numeric types that Core Data knows how to handle.属性都是 Core Data 知道如何处理的数字类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM