Function does not a return a multiple value(setter or getter) :-
.h
@interface product :NSObject{
NSString *pname;
int pcode;
float price;
}
-(void)setpname:(NSString*)pnm pcode:(int)pcd price :(float)pr;
-(void)getpname;
-(void)getpcode;
-(void)getprice;
@end
.m
@implementation-(void)setpname:(NSString*)pnm pcode:(int)pcd price :(float)pr{
pname=pnm;
pcode=pcd;
price=pr;
}
-(void)getpname{
return name;
}
-(void)getpcode
{
return pcode
}
-(void)getprice
{
return price;
}@end
Main program
#import "product.h"
product *obj =[product new];
[obj setpname:@"abc" pcode:101 price :101.1 ]
NSLog(@%@ pname is=,[getname]);
NSLog(@"%d pcode is=",[getpcode]);
NSLog(@%f price is=,[getprice]);
}
@end
Property & Syntehsize :-It is a keyword in a objective-c , its a request of a to compiler to generate a get and set methods for previously define property.
Syntax:-
.h
@property datatype variablename;
.m
@synthesize propertynamec ;
.h
@interface manager :NSObject{
int mcode;
NSString*mname;
float salary;
}
@property int mcode;
@property NSString *mname;
@property float salary;
@end
.m
@implemetation
@sysnthesize mcode,mname,salary;
@end
Main program
#import "manager.h"
manager*obj=[manager new];
obj.mcode=100;
obj.mname=@"shiv";
obj.salary=25000;
NSLog(@" manager code is=%d",mcode);
NSLog(@" manager name is=%@",mname);
NSLog(@" manager name is=%f",salary);
@end
.h
@interface product :NSObject{
NSString *pname;
int pcode;
float price;
}
-(void)setpname:(NSString*)pnm pcode:(int)pcd price :(float)pr;
-(void)getpname;
-(void)getpcode;
-(void)getprice;
@end
.m
@implementation-(void)setpname:(NSString*)pnm pcode:(int)pcd price :(float)pr{
pname=pnm;
pcode=pcd;
price=pr;
}
-(void)getpname{
return name;
}
-(void)getpcode
{
return pcode
}
-(void)getprice
{
return price;
}@end
Main program
#import "product.h"
product *obj =[product new];
[obj setpname:@"abc" pcode:101 price :101.1 ]
NSLog(@%@ pname is=,[getname]);
NSLog(@"%d pcode is=",[getpcode]);
NSLog(@%f price is=,[getprice]);
}
@end
Property & Syntehsize :-It is a keyword in a objective-c , its a request of a to compiler to generate a get and set methods for previously define property.
Syntax:-
.h
@property datatype variablename;
.m
@synthesize propertynamec ;
.h
@interface manager :NSObject{
int mcode;
NSString*mname;
float salary;
}
@property int mcode;
@property NSString *mname;
@property float salary;
@end
.m
@implemetation
@sysnthesize mcode,mname,salary;
@end
Main program
#import "manager.h"
manager*obj=[manager new];
obj.mcode=100;
obj.mname=@"shiv";
obj.salary=25000;
NSLog(@" manager code is=%d",mcode);
NSLog(@" manager name is=%@",mname);
NSLog(@" manager name is=%f",salary);
@end
No comments:
Post a Comment