Objective-C Tutorial
Learn Objective-C step by step: 38 lessons in 9 chapters with examples, quizzes, diagrams and projects.
Start learning →
of lessons completed
Getting Started
- What Is Objective-C? Learn what Objective-C is, where it came from, how messaging differs from function calls, and why it still matters for Apple platforms and legacy code bases.
- Setting Up and Your First Program Install an Objective-C toolchain on macOS, Linux or Windows, write a Hello World with Foundation, and learn what each line of the program does.
- Program Structure and NSLog Learn how Objective-C programs are organized into header and implementation files, how #import works, and how to print values with NSLog and printf format codes.
- Compiling with clang and GNUstep Learn the Objective-C build pipeline, the essential clang flags, how to compile multi-file programs with a Makefile, and how to read compiler errors and warnings.
Language Basics
- Variables and Data Types Learn Objective-C primitive types, NSInteger and CGFloat, BOOL, object pointers, id, nil and type casting, with sizes, ranges and common pitfalls explained.
- Operators and Expressions Learn Objective-C arithmetic, comparison, logical, bitwise and assignment operators, precedence rules, and why == is wrong for comparing strings and objects.
- Constants, Enums and typedef Learn how to define constants with const, #define and extern strings, create type-safe enums with NS_ENUM and NS_OPTIONS, and name types with typedef.
- Pointers and Structs Understand pointers, addresses, C arrays, structs and CGPoint-style value types in Objective-C, and see why every object is really a pointer to heap memory.
- Literals and Boxing Learn Objective-C literal syntax for NSString, NSNumber, NSArray and NSDictionary, how boxing with @() works, and how to unbox values and wrap structs in NSValue.
Control Flow and Functions
- Conditionals and switch Learn Objective-C decision making with if, else if, switch, enums and string comparisons, including nil checks, fallthrough rules and clean multi-branch patterns.
- Loops and Fast Enumeration Learn the for, while and do-while loops, break and continue, and the for-in fast enumeration syntax for arrays, dictionaries and sets, plus block-based enumeration.
- Functions Learn how to write C functions in Objective-C, pass values and pointers, return structs, use static inline helpers, and decide between a function and a method.
- Function Pointers and Recursion Learn how function pointers work, how to build callbacks and dispatch tables, how recursion solves problems like factorials and trees, and how selectors relate to both.
- Variadic Functions and Storage Classes Learn how to write variadic functions and methods with va_list, nil-terminated argument lists, and how static, extern, auto and register control scope and lifetime.
Objects and Classes
- Classes and Objects Learn how to declare a class with @interface, implement it with @implementation, create objects with alloc and init, use instance variables and self, and hide private details.
- Methods and Messages Learn Objective-C method declaration syntax, multi-argument messages and named parameters, selectors, self and super, return values, and why messaging nil is safe.
- Properties Learn @property declarations, generated accessors and ivars, attributes such as strong, weak, copy, nonatomic and readonly, dot syntax, and custom getters and setters.
- Initializers and dealloc Learn how to write init methods correctly, the designated initializer pattern, convenience initializers and factory methods, description overrides, and dealloc.
- Inheritance and Polymorphism Learn single inheritance in Objective-C, overriding methods, calling super, polymorphism with id and base class pointers, abstract class patterns and design guidance.
- Class Methods and Singletons Learn class methods with the + prefix, class objects and self in class scope, the +initialize and +load hooks, class properties, and how to build a thread-safe singleton.
Memory Management and ARC
- Reference Counting and Object Ownership Understand how Objective-C objects live and die - retain counts, ownership rules, retain, release and autorelease - the model that ARC automates, with a runnable C stand-in.
- Automatic Reference Counting (ARC) Learn how ARC inserts retain and release for you, which rules it follows, what it forbids, how to migrate from manual counting, and how to reason about object lifetime in modern Objective-C.
- Strong, Weak, Copy and Property Attributes Learn @property attributes in Objective-C - strong, weak, copy, assign, atomic, nonatomic, readonly - when to use each, why NSString needs copy, and how weak references zero out.
- Retain Cycles and Autorelease Pools Find and fix retain cycles with weak references, understand autorelease and @autoreleasepool blocks, spot leaks in loops, and learn the tools that catch memory problems in Objective-C code.
Protocols, Categories and Blocks
- Protocols and Delegation Learn Objective-C protocols - declaring and adopting them, @required and @optional methods, the delegate pattern, conformsToProtocol, id<Protocol> types and a C vtable stand-in.
- Categories and Class Extensions Add methods to existing Objective-C classes with categories, hide private details with class extensions, learn associated objects, naming rules and the pitfalls of overriding methods.
- Blocks - Closures in Objective-C Learn Objective-C blocks - the caret syntax, parameters and return types, typedefs, capturing variables, the __block modifier, copy semantics and using blocks as callbacks and completion handlers.
- Blocks and Grand Central Dispatch Run code concurrently in Objective-C with Grand Central Dispatch - serial and concurrent queues, dispatch_async, the main queue, groups, barriers, once, plus weak-self in async blocks.
Foundation Framework
- NSString and NSMutableString Work with text in Objective-C - string literals, formatting, comparing, searching, substrings, splitting and joining, NSMutableString, Unicode and why NSString length is not always what you expect.
- NSArray, NSDictionary and NSSet Master Foundation collections in Objective-C - literals, mutable and immutable variants, fast enumeration, sorting, filtering with predicates, generics, nil handling and a hash table stand-in.
- NSNumber, NSValue, NSData and Dates Box numbers in NSNumber and structs in NSValue, handle raw bytes with NSData, and work with NSDate, NSCalendar, NSDateComponents and formatters in Objective-C, with C stand-ins.
- NSError, Files and JSON Handle failures with NSError and out-parameters, read and write files with NSFileManager, and parse or generate JSON with NSJSONSerialization in Objective-C, plus exceptions vs errors.
Runtime and Interoperability
- The Objective-C Runtime and Message Sending See what really happens in [obj method] - objc_msgSend, selectors, the isa pointer, method lookup, dynamic resolution, forwarding, introspection and method swizzling in the Objective-C runtime.
- Key-Value Coding and Key-Value Observing Read and write properties by name with Key-Value Coding, use key paths and collection operators, and react to changes with Key-Value Observing, including context, removal rules and pitfalls.
- Interoperability with C, C++ and Swift Mix Objective-C with C and C++ (Objective-C++), call Objective-C from Swift and back with bridging headers and NS_SWIFT_NAME, annotate nullability, and map types across the boundary.
Projects and Practice
- Project: Bank Accounts and JSON Models Build a small Objective-C model layer - an Account class with validation and NSError, a Bank that owns accounts, and JSON in and out - then see the same logic run as a verified C stand-in.
- Project: An Observer and Notification Center Build your own notification center in Objective-C with weak observers, blocks and thread safety, learn how NSNotificationCenter works, and run the same event bus design as a C stand-in.
- Practice - Questions and Exercises Test your Objective-C with commonly asked interview questions on memory, properties, blocks, protocols and the runtime, plus hands-on exercises with solutions and runnable C stand-ins.