我之前使用过 Core Data 的可转换属性,但没有C
使用CMTime
.
我需要CMTime
使用可转换存储在核心数据上。
在 Model 对象上,我已将其声明为可转换的。
@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