Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Objective C Class and Object example
//gcc 5.0.4 #import <Foundation/Foundation.h> @interface Book : NSObject { NSString *title; NSString *author; int price; int weight; } -(void)setTitle:(NSString *)btitle setAuthor:(NSString *)bauthor; -(void)setPrice:(int)bprice; -(void)setWeight:(int)bweight; -(void)getBookDetails; -(void)resellPrice:(int)bweight; @end @implementation Book float priceperpaper = 5.3, resellprice; -(id) init { self = [super init]; title = @"Profession iOS Book"; author = @"ABC Author"; price = 100; weight = 1000; } -(void)setTitle:(NSString *)btitle setAuthor:(NSString *)bauthor { title = btitle; author = bauthor; } -(void)setPrice:(int)bprice { price=bprice; } -(void)setWeight:(int)bweight { weight=bweight; } -(void)getBookDetails { NSLog(@"Book \nTitle : %@ \nAuthor:%@, \nPrice:%d, \nWeight:%d",title,author,price,weight); } -(void)resellPrice:(int)bweight { weight=bweight; resellprice = weight / priceperpaper; NSLog(@"Resell Price = %f",resellprice); } @end int main (int argc, const char * argv[]) { Book *b1 = [[Book alloc] init]; [b1 getBookDetails]; [b1 setTitle:@"Vachnamrut" setAuthor:@"P.Muktanand Swamiji"]; [b1 setPrice:120]; [b1 setWeight:500]; [b1 getBookDetails]; [b1 resellPrice:500]; return 0; }
run
|
edit
|
history
|
help
0
string combine
muteble
enheritance
book
NSSet Program in objectice-c
Objective C NSSet Declaration
NSMutableStringProgram
NSMutableset(add/remove,Etraction,Intersect)
compound intresst in objective c
emp class