Objective-C Explained: The Language That Built the iPhone Era

Introduction: Before Swift, every iPhone app was written in Objective-C. Created in the 1980s by adding Smalltalk-style messaging to C, it became Apple's language through NeXT, macOS, and the first decade of iOS, and it still underpins much of Apple's older code. Its syntax looks strange at first, with square brackets and colons where other languages use dots, but that strangeness is its central idea: objects do not call methods, they send messages, and the runtime decides what happens next.

Messages, the runtime, and Cocoa: Message syntax: instead of object.method(argument), you write [object method:argument], and a method with several parts reads like a sentence, with each argument labelled. A dynamic runtime: messages are resolved at run time, so objects can forward messages, add methods, or respond in ways the compiler never saw, which powers much of Cocoa's flexibility. C underneath: Objective-C is a strict superset of C, so C code, pointers, and libraries work unchanged inside an Objective-C program. Cocoa frameworks: AppKit on macOS and UIKit on iOS, built on Objective-C, gave developers the windows, views, and controls that defined Apple software for decades.

Code (Objective-C):

#import <Foundation/Foundation.h>
@interface Greeter : NSObject
- (void)greet:(NSString *)name;
@end
@implementation Greeter
- (void)greet:(NSString *)name {
  NSLog(@"Hello, %@!", name);
}
@end
int main(int argc, const char * argv[]) {
  @autoreleasepool {
    Greeter *greeter = [[Greeter alloc] init];
    [greeter greet:@"Ayesha"];
  }
  return 0;
}

Explanation: @interface declares the class, @implementation defines it, NSLog prints with %@ for an object, and [greeter greet:@"Ayesha"] sends the greet message with its labelled argument. The brackets are the language.

The honest trade: Objective-C's trade is modernity and hiring: Swift is now Apple's preferred language, new projects rarely start in Objective-C, and its syntax and manual memory history (now mostly handled by ARC) feel dated to newcomers. When to reach for it: when maintaining or extending existing Apple codebases, where it is still essential; Swift for any new Apple project, where the tooling and community have moved.

The brackets that built an era: Objective-C is the language that built the iPhone era: C with Smalltalk messaging, a dynamic runtime, and Cocoa, in syntax that reads like sentences in square brackets. It trades modern tooling for history and depth, and for the codebases it still powers, that history is unavoidable.

Comments

Popular posts from this blog

Swift Explained: Apple's Language for iPhone, Mac, and More

Neovim Explained: Vim Rebuilt for the Modern Era

Rust Explained: Memory Safety Without a Garbage Collector