7. Программирование на Objective-C. Свойства классов и их инициализация



#import <Foundation/Foundation.h>


@interface Developer : NSObject {
    @private
    NSString *name;
    NSDate *birthday;
}
@property NSString *name;
- (void)printInfo;
- (NSDate *)birthday;
- (void)setBirthday:(NSDate *)value;
@end


@implementation Developer
@synthesize name;
- (id)init
{
    self = [super init];
    if (self)
    {
    }
    return self;
}
- (id)initWithName:(NSString *)n
{
    self = [super init];
    if (self)
    {
        name = n;
    }
    return self;
}
- (void)printInfo
{
    NSLog(@"name: %@\nbirthday: %@", name, birthday);
}
- (NSDate *)birthday
{
    return birthday;
}
- (void)setBirthday:(NSDate *)value
{
    birthday = value;
}
@end


int main(int argc, const char * argv[])
{
    @autoreleasepool
    {
        Developer *theDeveloper = [[Developer alloc] init];
        
        theDeveloper.birthday = [NSDate date];
        theDeveloper.name = @"John Smith";
        [theDeveloper printInfo];
        
        [theDeveloper setBirthday:[NSDate date]];
        [theDeveloper setName:@"Василий Пупкин"];
        [theDeveloper printInfo];
        
        Developer *theOtherDeveloper = [[Developer alloc] initWithName:@"Mahmud"];
    }
    return 0;
}