Objective-C
v12.2.0
Objective-C
v12.2.0
Objective-C is an object-oriented language that adds Smalltalk-style messaging on top of C. For decades it was the primary language for Apple's macOS and iOS development, built around classes, message sending with bracket syntax, and a dynamic runtime. It remains widely used in legacy Apple frameworks and interoperates cleanly with C and C++ code in mixed-language projects.
On CompileBytes, Objective-C programs are compiled with GCC (reported as version 12.2.0) rather than Apple's Clang, so platform-specific Cocoa frameworks like UIKit and Foundation may be unavailable. Plain C-style programs and basic Objective-C class definitions using the GNUstep runtime work well, making it suitable for learning the messaging syntax, memory model, and core language concepts without a Mac.
#import <stdio.h>
int main(void) {
printf("Hello, World!\n");
return 0;
}#import <objc/Object.h>
#import <stdio.h>
@interface Greeter : Object
- (void)greet:(const char *)name;
@end
@implementation Greeter
- (void)greet:(const char *)name {
printf("Hello, %s!\n", name);
}
@end
int main(void) {
Greeter *g = [Greeter new];
[g greet:"CompileBytes"];
return 0;
}#import <stdio.h>
long factorial(int n) {
return n <= 1 ? 1 : n * factorial(n - 1);
}
int main(void) {
for (int i = 1; i <= 5; i++) {
printf("%d! = %ld\n", i, factorial(i));
}
return 0;
}#import <stdio.h>
int main(void) {
char name[64];
printf("Enter your name: ");
if (scanf("%63s", name) == 1) {
printf("Hi, %s!\n", name);
}
return 0;
}#import <objc/Object.h>
#import <stdio.h>
@interface Calc : Object
- (int)add:(int)a to:(int)b;
@end
@implementation Calc
- (int)add:(int)a to:(int)b {
return a + b;
}
@end
int main(void) {
Calc *c = [Calc new];
printf("sum = %d\n", [c add:3 to:4]);
return 0;
}#import <stdio.h>
typedef struct {
int x;
int y;
} Point;
int main(void) {
Point p = {3, 4};
Point *ptr = &p;
printf("(%d, %d)\n", ptr->x, ptr->y);
return 0;
}#import <objc/Object.h>
#import <stdio.h>
@interface Counter : Object
{
int value;
}
- (void)increment;
- (int)value;
@end
@implementation Counter
- (void)increment { value++; }
- (int)value { return value; }
@end
int main(void) {
Counter *c = [Counter new];
[c increment];
[c increment];
printf("count = %d\n", [c value]);
return 0;
}#import <stdio.h>
int main(void) {
int nums[5] = {1, 2, 3, 4, 5};
int sum = 0;
for (int i = 0; i < 5; i++) {
sum += nums[i];
}
printf("sum = %d\n", sum);
return 0;
}Yes. CompileBytes compiles and runs your Objective-C code in the browser, so you don't need Xcode, a Mac, or any local toolchain installed.
Objective-C here is compiled with GCC, reported as version 12.2.0, using the GNUstep Objective-C runtime rather than Apple's Clang.
No. Those are Apple platform frameworks tied to Clang and macOS/iOS. The GCC-based environment supports core Objective-C, the base Object class, and standard C libraries.
Yes. Use scanf, getchar, or fgets to read from stdin, and provide the input through the input panel before running.
Yes, compiling and running Objective-C on CompileBytes is completely free.