Created
August 21, 2015 05:11
-
-
Save pminkov/75934b5c2763ee5dcadf 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
// | |
// main.m | |
// Objective | |
// | |
// Created by Petko Minkov on 8/20/15. | |
// Copyright (c) 2015 Petko. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
@interface Box : NSObject | |
{ | |
@public double length; | |
@public NSString *name; | |
} | |
-(double) volume; | |
-(id) initWithLength: (int) initLength; | |
-(id) initWithNameLength: (NSString*) name andLength:(int) length; | |
-(NSString *) fullTitle; | |
@end | |
@implementation Box | |
-(id) init | |
{ | |
length = 15; | |
name = @"The box"; | |
return self; | |
} | |
-(id) initWithLength: (int) initLength | |
{ | |
length = initLength; | |
return self; | |
} | |
-(id) initWithNameLength:(NSString *)initName andLength:(int)initLength { | |
name = initName; | |
length = initLength; | |
return self; | |
} | |
-(double) volume { | |
return length * length; | |
} | |
-(NSString *) fullTitle { | |
const char *namestr = [name UTF8String]; | |
NSString *title = [[NSString alloc] initWithFormat:@"Box name: %s, length: %.2f", namestr, length]; | |
return title; | |
} | |
@end | |
int main(int argc, const char * argv[]) | |
{ | |
@autoreleasepool { | |
NSLog(@"Hello, World!"); | |
Box *box1 = [[Box alloc]initWithNameLength:@"Hello box" andLength:5.2]; | |
int length = box1->length; | |
int volume = [box1 volume]; | |
NSString *title = [box1 fullTitle]; | |
NSLog(@"Length:%d\nVolume:%d\nTitle:%s", length, volume, [title UTF8String]); | |
} | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment