movie というカスタムクラスがあります。3 つのプロパティで簡単です。
.h
@interface WTAMovie : NSObject
@property (strong, nonatomic) NSImage *theImage;
@property (strong, nonatomic) NSString *theTittle;
@property (strong, nonatomic) NSString *theBlurb;
@end
.m には、プロパティのデフォルト値を設定する初期化子と、カスタム オブジェクトがログに記録されている場合にプロパティの値を返す記述メソッドがあります。このような。
-(NSString *)description
{
NSString *desc = [NSString stringWithFormat:@"<Movie> - theImage = %@, theTittle = %@, theBlurb = %@", _theImage, _theTittle, _theBlurb];
return desc;
}
-(id)init
{
self = [super init];
if (self) {
_theTittle = @"New Tittle";
_theBlurb = @"Empty Blurb";
NSString* imageName = [[NSBundle mainBundle] pathForResource:@"reel" ofType:@"png"];
_theImage = [[NSImage alloc] initWithContentsOfFile:imageName];
NSLog(@"from the person calss init: %@", _theImage);
}
return self;
}
私の Document.m ファイル初期化子では、新しい Movie オブジェクトを作成し、それをムービー オブジェクトを保持するように定義された配列に配置し、そのオブジェクトをログに記録しています。このような:
- (id)init
{
self = [super init];
if (self) {
// Add your subclass-specific initialization here.
_movies = [NSMutableArray new];
WTAMovie *firstMovie = [WTAMovie new];
[_movies addObject:firstMovie];
for (id object in _movies)
{
NSLog(@"%@", object);
}
}
return self;
}
コンソールの出力は次のとおりです。
2013-07-15 13:47:57.174 HomeworkFour[5044:303] - theImage = (null)、theTittle = 新しいタイトル、theBlurb = 空の Blurb
画像は常にnullだと言っていますか?わかりません。ご覧のとおり、プロジェクトに追加したファイルから設定しています????