Objective-C

Edit · View history

Objective-C

Objective-C is a general-purpose, object-oriented programming language that adds Smalltalk-style messaging to the C programming language. It was originally developed by Brad Cox and Tom Love in the early 1980s at their company Productivity Products International (PPI). The language gained widespread adoption as the primary development language for macOS and iOS applications under Apple Inc., where it was the standard for Cocoa and Cocoa Touch frameworks until the introduction of Swift in 2014.

Objective-C is a superset of C, meaning any valid C program is also a valid Objective-C program. Its key addition is a dynamic object system based on message passing, inspired by Smalltalk, which allows for runtime polymorphism and introspection. The language also includes features such as categories, protocols, and memory management via retain/release or automatic reference counting (ARC).

History

Objective-C originated in the early 1980s when Brad Cox and Tom Love sought to combine the efficiency of C with the flexibility of object-oriented programming. They created a preprocessor that translated Objective-C code into C, enabling it to run on any platform with a C compiler. In 1986, PPI released the first commercial version.

The language remained niche until the late 1980s when NeXT Computer adopted it for its NeXTSTEP operating system. After Apple acquired NeXT in 1997, Objective-C became the foundation of Apple’s development ecosystem. It was used to build the Cocoa and Cocoa Touch frameworks for macOS and iOS. With the rise of Swift, Objective-C usage declined but remains in active use for legacy codebases and interoperability with C and C++ libraries.

Features

Syntax

Objective-C uses square brackets for message sending: [object method] or [object methodWithArgument:arg]. Class declarations use @interface and @implementation directives, with instance variables enclosed in braces. Method prototypes include parameter labels and colons. The language also supports preprocessor directives, C-style function calls, and inline C code.

Example

A simple “Hello, World!” program:

```

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {

@autoreleasepool {

NSLog(@"Hello, World!");

}

return 0;

}

```

See also