Created
January 31, 2014 16:43
-
-
Save waitonza/8735903 to your computer and use it in GitHub Desktop.
Basic OOP in Objective-C
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
// | |
// Classroom.h | |
// SocketTest | |
// | |
// Created by Wairung Tiranalinvit on 1/31/2557 BE. | |
// Copyright (c) 2557 Wairung Tiranalinvit. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
#import "Student.h" | |
@interface Classroom : NSObject | |
- (void)addStudent:(Student*)student; | |
- (void)addStudentWithID:(NSString*)sid andName:(NSString*)name; | |
- (NSArray*)students; | |
@end |
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
// | |
// Classroom.m | |
// SocketTest | |
// | |
// Created by Wairung Tiranalinvit on 1/31/2557 BE. | |
// Copyright (c) 2557 Wairung Tiranalinvit. All rights reserved. | |
// | |
#import "Classroom.h" | |
#import "Student.h" | |
@implementation Classroom { | |
NSMutableArray *students; | |
} | |
- (id)init | |
{ | |
self = [super init]; | |
if (self) { | |
Student *ton = [[Student alloc] init]; | |
ton.studentID = @"A1"; | |
ton.studentName = @"TON"; | |
Student *test = [[Student alloc] init]; | |
test.studentID = @"A2"; | |
test.studentName = @"TEST"; | |
students = [[NSMutableArray alloc] initWithArray:@[ton, test]]; | |
} | |
return self; | |
} | |
- (void)addStudent:(Student*)student | |
{ | |
[students addObject:student]; | |
} | |
- (void)addStudentWithID:(NSString*)sid andName:(NSString*)name | |
{ | |
Student *student = [[Student alloc] init]; | |
student.studentID = sid; | |
student.studentName = name; | |
[students addObject:student]; | |
} | |
- (NSArray*)students | |
{ | |
return students; | |
} | |
@end |
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
// | |
// Student.h | |
// SocketTest | |
// | |
// Created by Wairung Tiranalinvit on 1/31/2557 BE. | |
// Copyright (c) 2557 Wairung Tiranalinvit. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
@interface Student : NSObject | |
@property (nonatomic, strong) NSString *studentID; | |
@property (nonatomic, strong) NSString *studentName; | |
@property (nonatomic) float currentGrade; | |
@end |
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
// | |
// Student.m | |
// SocketTest | |
// | |
// Created by Wairung Tiranalinvit on 1/31/2557 BE. | |
// Copyright (c) 2557 Wairung Tiranalinvit. All rights reserved. | |
// | |
#import "Student.h" | |
@implementation Student | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment