Hey,
I've learned classes in Objective-C but lately i've found something "weird" or I just didn't saw any example of people who done it:
I've created a new class, for example
Code:
@interface Car : NSObject {
NSString *carOwner;
NSString *carColor;
}
-(Car *) initWithCarOwner: (NSString *) owner andColor: (NSString *) color;
@end
When Im implementing the initwithcarownerandcolor I am allocating the memory for those two variables (somthing like):
Code:
{
carOwner = [[NSString alloc] initWithString: owner];
carColor = [[NSString alloc] initWithString: color];
}
But what if the user wont initialize the object from this method, and instead will do:
Code:
Car *c = [[Car alloc] init];
Those variables wont be initialized (Or they are?) so.. what I need to do? maybe I need to implement the init method? (I just don't know because I'm reading an Objective-C book but I never saw an example with init override...)
Looking forward your help, thanks!