Objective-C is a programming language created in 1984 by Brad Cox.
#33on PLDB | 40Years Old | 536kRepos |
Objective-C is a general-purpose, object-oriented programming language that adds Smalltalk-style messaging to the C programming language. It was the main programming language used by Apple for the OS X and iOS operating systems, and their respective application programming interfaces (APIs) Cocoa and Cocoa Touch prior to the introduction of Swift. The programming language Objective-C was originally developed in the early 1980s. Read more on Wikipedia...
#import <Foundation/Foundation.h>
int main() {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSLog(@"Hello, world!");
[pool drain];
return 0;
}
/*
Build on OS X:
clang -framework Foundation -fobjc-arc objc.m -o objc
Build on Linux with GNUstep:
clang `gnustep-config --objc-flags` `gnustep-config --base-libs` -fobjc-nonfragile-abi -fobjc-arc objc.m -o objc
*/
#import <Foundation/Foundation.h>
int main(void)
{
NSLog(@"Hello World");
}
/* Hello World in Objective-C.
** Since the standard implementation is identical to K&R C,
** a version that says hello to a set of people passed on
** the command line is shown here.
*/
#include <stdio.h>
#include <objpak.h>
int main(int argc,char **argv)
{
id set = [Set new];
argv++;while (--argc) [set add:[String str:*argv++]];
[set do:{ :each | printf("hello, %s!\n",[each str]); }];
return 0;
}
#import "Foo.h"
@implementation Foo
@end
-(void) firstLabel: (int)param1 secondLabel: (int)param2;
auto break case char const continue default do double else enum extern float for goto if inline int long register restrict return short signed sizeof static struct switch typedef union unsigned void volatile while _Bool _Complex _Imaginary BOOL Class bycopy byref id IMP in inout nil NO NULL oneway out Protocol SEL self Super YES @ @interface @end @implementation @protocol @class @public @protected @private @property @try @throw @catch() @finally @synthesize @dynamic @selector atomic nonatomic retain
Feature | Supported | Example | Token |
---|---|---|---|
Standard Library | ✓ | NSLog(@"Hello, World!"); | |
Explicit Standard Library | ✓ |
#include |
|
Conditionals | ✓ | ||
Switch Statements | ✓ | ||
Constants | ✓ | ||
While Loops | ✓ | ||
MultiLine Comments | ✓ | /* A comment */ | /* */ |
Print() Debugging | ✓ | printf | |
Comments | ✓ | // A comment | |
Message Passing | ✓ | ||
Line Comments | ✓ | // A comment | // |
Interfaces | ✓ | @protocol Printing -(void) print; @end | |
File Imports | ✓ |
// #import ensures that a file is only ever included once so that you never have a problem with recursive includes.
#import |
|
Constructors | ✓ | ||
Pointers | ✓ | ||
Single Dispatch | ✓ | ||
Strings | ✓ | "hello world" | " |
Case Insensitive Identifiers | X | ||
Semantic Indentation | X | ||
Operator Overloading | X | ||
Garbage Collection | X |