【发布时间】:2018-03-10 18:12:49
【问题描述】:
我之前使用过 Core Data 的可转换属性,但没有使用 C 对象,例如 CMTime。
我需要使用可转换在 Core Data 上存储 CMTime。
在模型对象上,我已将其声明为可变形。
@property (nonatomic, retain) id tempo;
我知道CMTime 是一个C 对象,我需要将其转换为 NSDictionary 并对其进行序列化,以便存储在 Core Data 上。
在NSManagedObject 课堂上,我有这个...
+(Class)transformedValueClass
{
return [NSData class];
}
+(BOOL) allowsReverseTransformation
{
return YES;
}
-(id)transformedValue:(id) value
{
CFDictionaryRef dictTime = CMTimeCopyAsDictionary(?????, kCFAllocatorDefault);
NSDictionary *dictionaryObject = [NSDictionary dictionaryWithDictionary:(__bridge NSDictionary * _Nonnull)(dictTime)];
return [NSKeyedArchiver archivedDataWithRootObject:dictionaryObject];
}
-(id)reverseTransformedValue:(id)value
{
// not complete ???
return (NSDictionary*) [NSKeyedUnarchiver unarchiveObjectWithData:value];
}
????? 是我的问题。你看,transformedValue:(id)value 方法接收的值是id,但我需要一个CMTime。我不能简单地施放它。
另外,当我创建这个实体的一个实例时,理论上我应该能够这样分配值:
myEntity.tempo = myCmTimeValue;
我不知道如何对 id 这样做...
另外,在reverseTransformedValue: 上,我将返回id。
我不明白。我希望能够设置和接收CMTime
【问题讨论】:
标签: ios objective-c core-data cmtime