0

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????

Tommy Alexander
  • 701
  • 1
  • 7
  • 17
  • at a quick glance tommy i think your properties are jacked up. Here is a quick reference to the properties attributes. http://stackoverflow.com/questions/9859719/xcode-property-attributes-nonatomic-copy-strong-weak – apollosoftware.org Jul 15 '13 at 18:11
  • Have you tried using UIImage instead of NSImage? – apollosoftware.org Jul 15 '13 at 18:14
  • it will always show up as null. Only thing you can assign is the name property, if it's not assigned it'll show nil. However the image is loaded in there. It just simply won't show a name without being assigned. Once the image is loaded, it has no further knowledge about it's resource. – apollosoftware.org Jul 15 '13 at 18:24

1 Answers1

0

OK, this ended up being something dumb. My image resource was a .jpeg and in my: [[NSBundle mainBundle] pathForResource:@"reel" ofType:@"png"];

I had obviously given an ofType of png.

One comment though, it is not the case that NSImage will always show null in the descriptor when logged to the console. Once the NSImage is initialized correctly when logged out the object will show several pieces of information about the object like memory location and certain on screen drawing parameters.

Tommy Alexander
  • 701
  • 1
  • 7
  • 17