I am newbie to Objective-C. I have a 'XYZPerson' Class with attributes {firstName, lastName, dateOfBirth} and I want when I write "XYZPerson *person=[[XYZPerson alloc] init]" in main, it should call my overridden 'init' method which should in-turn call my designated initializer and initializes my object with the defined values.
My Code snippets. http://pastebin.com/FfxNDDhf
#import <Foundation/Foundation.h>
#import "XYZShoutingPerson.h"
int main(int argc, const char * argv[])
{
@autoreleasepool {
XYZPerson *person=[[XYZPerson alloc] init];
if(person) {
[person sayHello];
}
else {
NSLog(@"Person Object is NULL");
}
}
return 0;
}
-(id)init
{
self=[super init];
return [self initWithFirstName:@"Ankit" LastName:@"Sehra" DOB:01/01/2000];
}
-(id)initWithFirstName:(NSString *)aFirstName LastName:(NSString *)aLastName DOB:(NSDate *)aDateOfBirth
{
_firstName=aFirstName;
_lastName=aLastName;
_dateOfBirth=aDateOfBirth;
}
-(void)sayHello;
{
NSLog(@"%@ %@ %@",self.firstName,self.lastName,self.dateOfBirth);
}
Write now the output of the program is "Person Object is NULL", I want it to print the firstName, lastName and DOB.
XYZPerson .h / .m
?