NSDate And Super Class
NSDate And Super Class
- Subject: NSDate And Super Class
- From: Richard Good <email@hidden>
- Date: Tue, 24 Feb 2009 17:25:10 -0800
I clearly don't understand how inheritance works for Objective C, at
least not with the NSDate type. When I create a super class with an
NSDate type as an instance variable and then instantiate a subclass of
the superclass, I get an "out of Scope" error for the NSDate instance
variable.
What am I doing wrong?
Here is an example of my class hierarchy:
Super Class:
DateTest.h
#import <Foundation/Foundation.h>
@interface DateTest : NSObject {
NSDate* aDate;
}
@property (nonatomic,retain) NSDate* aDate;
@end
DateTest.m
#import "DateTest.h"
@implementation DateTest
@synthesize aDate;
-(DateTest*) init {
[super init];
aDate =[NSDate date];
return self;
}
@end
Sub Class:
DatesubClass.h
#import <Foundation/Foundation.h>
#import "DateTest.h"
@interface DatesubClass : DateTest {
NSString* testStr;
}
@property (nonatomic,copy) NSString* testStr;
@end
SubClass DatesubClass.m
#import "DatesubClass.h"
@implementation DatesubClass
@synthesize testStr;
-(DatesubClass*) init {
[super init];
testStr= @"Test";
return self;
}
@end
Instance var creation
DatesubClass* datesubClass = [[DatesubClass alloc]init];
At this point the datesubClass.aDate Instance variable is "out of scope"
Richard Good
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden