aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArslaan Pathan <[email protected]>2026-10-01 22:31:20 +1300
committerArslaan Pathan <[email protected]>2026-10-01 22:31:20 +1300
commit2cdf144528f006b3c4d4404d1099b8d40ee54277 (patch)
tree0fdb0fe3e33e4987158b79df1bed378b62be783d
parent99f4a811477b51824d6eddeed3dc4aeb41698ea1 (diff)
downloadobjc-test-2cdf144528f006b3c4d4404d1099b8d40ee54277.tar.xz
objc-test-2cdf144528f006b3c4d4404d1099b8d40ee54277.zip
player count/global var in implementation test
-rw-r--r--main.m17
1 files changed, 17 insertions, 0 deletions
diff --git a/main.m b/main.m
index 0ee0fc5..c256e2b 100644
--- a/main.m
+++ b/main.m
@@ -60,16 +60,20 @@
- (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;
@@ -91,6 +95,10 @@
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) {
@@ -108,7 +116,16 @@ int main(void) {
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;
}