views:

56

answers:

2

I have this method in my Car.h class file:

@interface Car : NSObject {
NSString * name;
UIImage* image; 
}


+ (id)withName:(NSString *)name withImage:(UIImage *)image; 
@end

and my Car.m class file:

#import "Car.h"
@implementation Car
@synthesize name, image;

+ (id)withName:(NSString *)name withImage:(UIImage *)image {
Car *newCar = [[[self alloc] init] autorelease];

newCar.name = name;
newCar.image = image;
return newCar;
}

Now I have a MutableArray in a ViewController where I add new Car objects like this:

[myMutableArray addObject:[Car withName:name withImage:image];

But it crashes if image is anything but nil. I can return the name but it doesn't work with anything else but Strings. Could you help me please?

A: 

You don't appear to have @property declaration in your interface file

ennuikiller
+1  A: 

I'm assuming the @property omission is a typo (there's also a bracket missing from the last line of code), since I imagine that'd throw a compiler error. How are you getting image? Also, make sure your properties are set to retain, not just assign.

Ben Gottlieb
You were right, I did @property (copy) instead of retain, thanks alot everyone.
hecta