Created
August 31, 2014 23:07
-
-
Save prasadwrites/a13b014949444af165dc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//compiled with compileonline.com | |
//http://www.compileonline.com/compile_objective-c_online.php | |
//also compiled using GNUSetup on windows. | |
#import <Foundation/Foundation.h> | |
@interface Book : NSObject | |
{ | |
char * title; | |
char * author; | |
int year; | |
} | |
@property char * title; | |
@property char * author; | |
@property int year; | |
@end | |
@implementation Book | |
-(id)init | |
{ | |
self = [super init]; | |
if (self) { | |
title = "TitleDefault"; | |
author = "AuthorDefault"; | |
year = 1800; | |
} | |
return self; | |
} | |
-(id)init:(char *)aTitle auth:(char *)aAuthor ypub:(int)aYear; | |
{ | |
self = [super init]; | |
if (self) { | |
title = aTitle; | |
author = aAuthor; | |
year = aYear; | |
} | |
return self; | |
} | |
@synthesize title; | |
@synthesize author; | |
@synthesize year; | |
@end | |
int main (int argc, const char * argv[]) | |
{ | |
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; | |
// Create book1 object of type Book | |
Book *book1 = [[Book alloc]init ]; | |
// Create book2 object of type Book | |
Book *book2 = [[Book alloc]init : "Author Name" auth:"Title Name" ypub:1900]; | |
NSLog(@"%s", [book1 title]); | |
NSLog(@"%s", [book1 author]); | |
NSLog(@"%d", [book1 year]); | |
NSLog(@"\n"); | |
NSLog(@"%s", [book2 title]); | |
NSLog(@"%s", [book2 author]); | |
NSLog(@"%d", [book2 year]); | |
NSLog(@"\n"); | |
[book1 setTitle:"Objective C Fundamentals"]; | |
[book1 setAuthor:"Prasad Nair"]; | |
[book1 setYear:2014]; | |
NSLog(@"%s", [book1 title]); | |
NSLog(@"%s", [book1 author]); | |
NSLog(@"%d", [book1 year]); | |
NSLog(@"\n"); | |
[book2 setTitle:"Advanced Objective C"]; | |
[book2 setAuthor:"Prasad Nair"]; | |
[book2 setYear:2015]; | |
NSLog(@"%s", [book2 title]); | |
NSLog(@"%s", [book2 author]); | |
NSLog(@"%d", [book2 year]); | |
[pool drain]; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment