diff options
| author | Arslaan Pathan <[email protected]> | 2026-10-01 22:18:26 +1300 |
|---|---|---|
| committer | Arslaan Pathan <[email protected]> | 2026-10-01 22:18:26 +1300 |
| commit | 99f4a811477b51824d6eddeed3dc4aeb41698ea1 (patch) | |
| tree | 7c435d987f61eed39636d89ace7c5ee3adfdee2b /main.m | |
| parent | 5fcfe66bb16e41a8cf8a96f3609b869bff144ec9 (diff) | |
| download | objc-test-99f4a811477b51824d6eddeed3dc4aeb41698ea1.tar.xz objc-test-99f4a811477b51824d6eddeed3dc4aeb41698ea1.zip | |
i kinda forgot to commit because i was learning abt objective-c so have fun (i added a ton of classes and stuff ig)
Diffstat (limited to 'main.m')
| -rw-r--r-- | main.m | 92 |
1 files changed, 92 insertions, 0 deletions
@@ -3,20 +3,112 @@ #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; +@end + +@implementation Player + +- (instancetype)init { + self = [super init]; + if (self) { + x = 0; + y = 0; + name = @"Player"; + } + + 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); +} + +@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 sayHi]; + return 0; } |
