Skip to content

Instantly share code, notes, and snippets.

@pminkov
Created August 21, 2015 05:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pminkov/75934b5c2763ee5dcadf to your computer and use it in GitHub Desktop.
Save pminkov/75934b5c2763ee5dcadf to your computer and use it in GitHub Desktop.
//
// 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