2011-12-30 23 views
0

なぜ親からの子オブジェクトのプロパティへの参照を作成できないのか分かりません。ここ親オブジェクトからネストされたオブジェクトを参照する

@class Vegetable; 

@interface MyVegetableGarden : NSManagedObject 

@property (nonatomic) NSTimeInterval datecreated; 
@property (nonatomic) NSTimeInterval datemodified; 
@property (nonatomic) BOOL active; 
@property (nonatomic, retain) Vegetable *vegetable; 

@end 

と野菜のクラスされています:ここでは関係がある

MyVegetableGarden *v = [[MyVegetableGarden alloc] init]; 

v.vegetable.name // For some reason the compiler says that name property is not found 
:今

#import <Foundation/Foundation.h> 
#import <CoreData/CoreData.h> 

@class VegetableCategory; 

@interface Vegetable : NSManagedObject 

@property (nonatomic, retain) NSString * about; 
@property (nonatomic) BOOL active; 
@property (nonatomic) NSTimeInterval dateCreated; 
@property (nonatomic) NSTimeInterval dateModified; 
@property (nonatomic, retain) NSString * imageURL; 
@property (nonatomic, retain) NSString * name; 
@property (nonatomic, retain) VegetableCategory *vegetableCategory; 

@end 

、私は次のコードを使用して野菜クラスのnameプロパティにアクセスしようとしています

+1

VegetableとMyVegetableGardenをインポートしていますか? –

答えて

1

名前にアクセスするファイルに#imported Vegetable.hがあることを確認してください。

+0

クリスおかげさま!それが問題でした!私はあなたの答えを数分で受け入れます。 – azamsharp

1

私はsuではありませんあなたがそのようなNSManagedObjectを作成することができます再:

S

docs状態

あなたが直接管理対象オブジェクトをインスタンス化する場合は、指定イニシャライザ(initWithEntity:insertIntoManagedObjectContext:)を呼び出す必要があります。

はまた

重要を参照してください:このメソッドは、NSManagedObjectのための指定イニシャライザです。管理オブジェクトをinitに送信するだけで管理オブジェクトを初期化してはなりません。

関連する問題