Tuesday, July 22, 2014

Custom Object Class

#import <Foundation/Foundation.h>

@interface Person : NSObject


@property(nonatomic,strong)NSString *firstName;
@property(nonatomic,strong)NSString *lastName;

-(id)initWithAdrianFirstName:(NSString*)firstName
                withLastName:(NSString*)lastName;
-(NSString*)description;


@end

#import "Person.h"

@implementation Person

-(id)initWithAdrianFirstName:(NSString *)firstName withLastName:(NSString *)lastName
{
    self=[super init];
    self.firstName=firstName;
    self.lastName=lastName;
    return self;
    
}

-(NSString*)description{
    
    return [NSString stringWithFormat:@"%@,%@",self.firstName,self.lastName];
}

@end


- (void)viewDidLoad
{
Person *p=[[Person alloc]initWithAdrianFirstName:@"dhanushka" withLastName:@"Adrian"] ;
    personLable.text=[p description];

}

No comments:

Post a Comment