Objective-C Runtime

The dynamic heart of Objective-C: objects, classes and messages, resolved while your app runs.

Introduced
2001
Mac OS X 10.0
Kind
Framework
Runs on
Get it from
iOS
2.0+
iPadOS
2.0+
Mac Catalyst
13.0+
macOS
10.0+
tvOS
9.0+
visionOS
1.0+
watchOS
2.0+

Overview

The Objective-C Runtime is the library that makes Objective-C dynamic. Every method call is a message the runtime delivers while your app runs, looking up the right implementation at that moment. That's what lets you add methods, swap implementations and inspect classes on the fly.

It also defines NSObject, the root of most Cocoa classes. You rarely need to call it directly today, but it's still underneath UIKit and AppKit, and Swift uses it whenever you mark code with @objc.

Message sending

Every method call is a message, matched to its code at run time.

NSObject

The root class that gives objects their basic runtime behavior.

Method swizzling

Swap or add method implementations while the app is running.

Introspection

Ask any class for its methods, properties and protocols.

Greeter.h / Greeter.m
// Greeter.h #import <Foundation/Foundation.h> @interface Greeter : NSObject @property (nonatomic, copy) NSString *name; - (instancetype)initWithName:(NSString *)name; - (NSString *)greeting; @end // Greeter.m #import "Greeter.h" @implementation Greeter - (instancetype)initWithName:(NSString *)name { self = [super init]; if (self) { _name = [name copy]; } return self; } - (NSString *)greeting { NSInteger hour = [[NSCalendar currentCalendar] component:NSCalendarUnitHour fromDate:[NSDate date]]; NSString *part = hour < 12 ? @"Good morning" : hour < 18 ? @"Good afternoon" : @"Good evening"; return [NSString stringWithFormat:@"%@, %@!", part, self.name]; } @end

History

How it grew up.

1984

Objective-C is born

Brad Cox and Tom Love add Smalltalk-style messaging to C.

1988

NeXTSTEP

NeXT adopts Objective-C for its operating system and frameworks.

2001

Mac OS X and Cocoa

The runtime ships at the core of Mac OS X, under every Cocoa app.

2007

Objective-C 2.0

Properties, fast enumeration and a modernized runtime arrive with Mac OS X Leopard.

2011

Automatic Reference Counting

The compiler takes over retain and release.

2014

Swift arrives

Swift works with Objective-C code through the same runtime.