Skip to content

Instantly share code, notes, and snippets.

@imack
Last active August 29, 2015 14:16
Show Gist options
  • Save imack/68a28392390f78194d83 to your computer and use it in GitHub Desktop.
Save imack/68a28392390f78194d83 to your computer and use it in GitHub Desktop.
Cool Student Classroom
//
// Classroom.h
// LighthouseClassroom
//
// Created by Ian MacKinnon on 2015-07-02.
// Copyright (c) 2015 Ian MacKinnon. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface Classroom : NSObject
@property(nonatomic, strong) NSMutableArray *students;
@end
//
// Classroom.m
// LighthouseClassroom
//
// Created by Ian MacKinnon on 2015-07-02.
// Copyright (c) 2015 Ian MacKinnon. All rights reserved.
//
#import "Classroom.h"
@implementation Classroom
-(instancetype) init{
self = [super init];
if (self){
self.students = [[NSMutableArray alloc] init];
}
return self;
}
@end
//
// CoolStudent.h
// LighthouseClassroom
//
// Created by Ian MacKinnon on 2015-07-02.
// Copyright (c) 2015 Ian MacKinnon. All rights reserved.
//
#import "Student.h"
@interface CoolStudent : Student
-(void) takeSelfie;
@end
//
// CoolStudent.m
// LighthouseClassroom
//
// Created by Ian MacKinnon on 2015-07-02.
// Copyright (c) 2015 Ian MacKinnon. All rights reserved.
//
#import "CoolStudent.h"
@implementation CoolStudent
-(void) takeSelfie{
NSLog(@"Cool Student took a #selfie");
}
-(void) morningGreeting{
//[super morningGreeting];
NSLog(@"'sup my bros");
}
@end
//
// main.m
// LighthouseClassroom
//
// Created by Ian MacKinnon on 2015-07-02.
// Copyright (c) 2015 Ian MacKinnon. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "Student.h"
#import "CoolStudent.h"
#import "Classroom.h"
int main(int argc, const char * argv[]) {
@autoreleasepool {
Student *student1 = [[Student alloc] init];
[student1 setAge:26];
NSLog(@"Student's age is: %d", student1.age);
NSLog(@"Student slept %d hours", student1.hoursSlept);
Student *student2 = [[CoolStudent alloc] init];
[student2 setAge:28];
Student *student3 = [[Student alloc] init];
[student2 setAge:24];
NSLog(@"Cool Student's age is: %d", [student2 age]);
NSLog(@"Cool Student slept %d hours", [student2 hoursSlept]);
//[student2 takeSelfie];
NSLog(@"=================");
Classroom *frontBoardroom = [[Classroom alloc] init];
[frontBoardroom.students addObject:student1];
[frontBoardroom.students addObject:student2];
[frontBoardroom.students addObject:student3];
for (Student *student in frontBoardroom.students){
[student morningGreeting];
}
}
return 0;
}
//
// Student.h
// LighthouseClassroom
//
// Created by Ian MacKinnon on 2015-07-02.
// Copyright (c) 2015 Ian MacKinnon. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface Student : NSObject
@property(nonatomic, assign) int age;
-(int) hoursSlept;
-(void) morningGreeting;
@end
//
// Student.m
// LighthouseClassroom
//
// Created by Ian MacKinnon on 2015-07-02.
// Copyright (c) 2015 Ian MacKinnon. All rights reserved.
//
#import "Student.h"
@implementation Student {
int _numberOfHoursSlept;
}
-(instancetype) init{
self = [super init];
if (self){
_numberOfHoursSlept = 7;
}
return self;
}
-(int) hoursSlept{
return _numberOfHoursSlept -3;
}
-(void) morningGreeting{
NSLog(@"Good Morning Everyone");
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment