I have a custom class called movie. It is simple with three properties:
.h
@interface WTAMovie : NSObject
@property (strong, nonatomic) NSImage *theImage;
@property (strong, nonatomic) NSString *theTittle;
@property (strong, nonatomic) NSString *theBlurb;
@end
the .m has an initializer that sets some default values for the properties and a description method returning the values of the properties if the custom object is logged. Like this.
-(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;
}
In my Document.m file initializer I am creating a new Movie object, putting it in an array defined to hold the movie objects and then logging that object. like this:
- (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;
}
THe output in the console is:
2013-07-15 13:47:57.174 HomeworkFour[5044:303] - theImage = (null), theTittle = New Tittle, theBlurb = Empty Blurb
THe image is ALWAYS saying it is null? I do not get it. As you can see I am setting it from a file that I added to the project????