2012-02-29 9 views
2

私はCoreDataで一時的なプロパティ属性を使用しようとしています。最終的に、私は実行時にのみデータベースに保存されるオブジェクトを作成しようとしています。プロパティのCoreDataの一時的な属性

私のセッターとゲッター:

-(AVMutableComposition *) composition 
{ 
    AVMutableComposition *composition; 
    [self willAccessValueForKey:@"composition"]; 
    composition = [self primitiveValueForKey:@"composition"]; 
    [self didAccessValueForKey:@"composition"]; 
    if (composition == nil) 
    { 
     self.composition = [AVMutableComposition composition]; 
    } 

return composition; 
} 
- (void)setComposition:(AVMutableComposition*)aComposition 
{ 
    [self willChangeValueForKey:@"composition"]; 
    [self setPrimitiveValue:aComposition forKey:@"composition"]; 
    [self didChangeValueForKey:@"composition"]; 
} 

私はそれが最初から毎回それを作成していたし、今それだけで正常に動作していない初めに、私の新しい作成されたオブジェクトに問題があります。

初回にオブジェクトを1回作成してからgetterを呼び出すたびに同じものを使用するには、適切なセッターとゲッターを作成する方法についてアドバイスできますか?

ありがとうございました。

答えて

0

私はコアデータを非常に基本的に理解しており、私はこの問題に取り組んできました。 NSManagedObjectサブクラスがある場合は、カテゴリを介してインスタンス変数を追加することはできません。セッター、ゲッター、プロパティは追加できますが、追加のストレージは追加できません。

その一時的なことは面白いと思います。これを行うもう一つの方法は、あなたのNSManagedObjectに対応する "通常の"オブジェクト(NSObjectのサブクラス)を持ち、必要な非CoreDataプロパティ(storage ivarsを含む)を持っていることです。だから、のようなものになります。

(証券はCoreDataの実体である)を

ComboClass.h:

#import <Foundation/Foundation.h> 
#import "Stock.h" 

@interface ComboClass : NSObject 

@property (weak, nonatomic) Stock *stock; 
@property (strong, nonatomic) NSDictionary *nonPersistentDictionary; 

@end 

ComboClass.m:

#import "ComboClass.h" 

@implementation ComboClass 

@synthesize stock = _stock; 
@synthesize nonPersistentDictionary = _nonPersistentDictionary; 

- (Stock*)stock { 
    // retrieve the stock from CoreData using a fetchedResultsController 
    return _stock; 
} 

- (NSDictionary*)nonPersistentDictionary { 
    if (!_nonPersistentDictionary) { 
     _nonPersistentDictionary = [[NSDictionary alloc] init]; 
    } 
    return _nonPersistentDictionary; 
} 

@end 

幸運、

Damien

関連する問題