[英]Trying to store CMTime as Transformable property on Core Data
我之前使用过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
CMTime
是一个结构, NSValueTransformer
只能与对象(指针)一起使用。
解决方法是将CMTime
包装在NSValue
@property (nonatomic, retain) NSValue *tempo;
并将NSValue
转换为CMTime
,反之亦然
CMTime time = [self.tempo CMTimeValue];
self.tempo = [NSValue valueWithCMTime:time];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.