Top 1,000 Features Creators Resources Blog Explorer Download
GitHub icon

Objective-C

< >

Objective-C is a programming language created in 1984 by Brad Cox.

#38on PLDB 40Years Old 536kRepos

Try now: Riju

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...


Example from Riju:
#import <Foundation/Foundation.h> int main() { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSLog(@"Hello, world!"); [pool drain]; return 0; }
Example from hello-world:
/* 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; }
Example from Linguist:
#import "Foo.h" @implementation Foo @end
Example from Wikipedia:
-(void) firstLabel: (int)param1 secondLabel: (int)param2;
Objective-C Keywords
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

Language features

Feature Supported Token Example
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 
#include 
#include 
Constructors โœ“
Pointers โœ“
Single Dispatch โœ“
Strings โœ“ "
"hello world"
Case Insensitive Identifiers X
Semantic Indentation X
Operator Overloading X
Garbage Collection X

View source

- Build the next great programming language ยท About ยท Acknowledgements ยท Extensions ยท Day 626 ยท feedback@pldb.io