[英]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.