Could someone help me out with this basic thing? I'm not able to set or get properties of a subclassed object.
Header:
Implementation:
After creating Car carA, this code puts a (null) in Console:
It seems I'm not setting the property correctly but I don't see where I'm going wrong. I've tried setting it in other places besides init as well.
Header:
Code:
#import <UIKit/UIKit.h>
@interface Car : NSObject {
NSNumber *position;
}
- (NSNumber *)position;
- (void)setPosition:(NSNumber *)newPosition;
@end
Implementation:
Code:
#import "Car.h"
@implementation Car
- (id)init {
[self setPosition:[NSNumber numberWithInt:42]];
return self;
}
- (NSNumber *)position{
return [[position retain] autorelease];
}
- (void)setPosition:(NSNumber *)newPosition{
if (position != newPosition){
[position release];
position = [newPosition copy];
}
}
- (void)dealloc {
[super dealloc];
}
@end
After creating Car carA, this code puts a (null) in Console:
Code:
NSLog(@"Position set to %@", [carA position]);
It seems I'm not setting the property correctly but I don't see where I'm going wrong. I've tried setting it in other places besides init as well.