blob: c256e2b63b3649540a00a7b8649b9e228ac33373 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
#include <Foundation/Foundation.h>
#include <objc/Object.h>
#include <stdio.h>
@interface Hello : NSObject
+ (instancetype)new;
- (void)sayHello;
@end
@implementation Hello
+ (instancetype)new {
return [[self alloc] init];
}
- (void)sayHello {
printf("Hello from Objective-C!\n");
}
@end
@interface ExtendedHello: Hello
- (void)sayHello;
- (void)baldNiko;
@end
@implementation ExtendedHello
- (void)baldNiko {
printf("67 67 bald niko 67\n");
}
- (void)sayHello {
[super sayHello];
[self baldNiko];
}
@end
@interface DoubleExtendedHello: ExtendedHello
- (void)baldNiko;
@end
@implementation DoubleExtendedHello
- (void)baldNiko {
printf("bald niko with CHEESE !!!\n");
}
@end
@interface Player : NSObject {
int x;
int y;
NSString *name;
}
- (instancetype)init;
- (void)setX:(int)x;
- (void)setY:(int)y;
- (void)setName:(NSString *)name;
- (void)sayHi;
+ (int)playerCount;
@end
@implementation Player
static int playerCount = 0;
- (instancetype)init {
self = [super init];
if (self) {
x = 0;
y = 0;
name = @"Player";
playerCount++;
}
return self;
}
- (void)setX:(int)val {
x = val;
}
- (void)setY:(int)val {
y = val;
}
- (void)setName:(NSString *)val {
name = val;
}
- (void)sayHi {
printf("Hello, I'm %s, and I am at X: %d, Y: %d!\n", [name UTF8String], x, y);
}
+ (int)playerCount {
return playerCount;
}
@end
int main(void) {
Hello *hello = [Hello new];
[hello sayHello];
NSString *string = @"Test\n";
printf([string UTF8String]);
ExtendedHello *ehello = [ExtendedHello new];
[ehello sayHello];
DoubleExtendedHello *dehello = [DoubleExtendedHello new];
[dehello sayHello];
Player *player = [Player new];
[player setName:@"John Hackclub"];
[player setX:27];
[player setY:538];
[player sayHi];
printf("player count: %d\n", [Player playerCount]);
Player *player2 = [Player new];
[player2 setName:@"French Hacker"];
[player2 setX:67];
[player2 setY:41];
[player2 sayHi];
printf("player count: %d\n", [Player playerCount]);
return 0;
}
|