Language basics
27 steps in 9 sets of Objective-C.
Objective-C is C with a Smalltalk soul: message sends in square brackets bolted onto plain C in 1984, licensed by NeXT, and carried into every Mac and iPhone ever shipped. For three decades it was how you wrote for Apple platforms, and it still runs enormous codebases there — Swift interoperates with it precisely because so much of the world underneath is still Objective-C. Its dynamism is the point: messages resolve at run time, nil absorbs them quietly, and classes are objects you can question.
This tour types the essentials: the autorelease-pool main, NSString and the format specifiers, message sends and interleaved selectors, alloc/init and the designated-initializer dance, @interface and @property, the collection literals with their mutable subclasses, fast and block enumeration, comparator sorting, blocks with capture and __block, protocols, categories, dynamic typing with id, NSNumber boxing, NSRange, and NS_ENUM. The Encore is the cross-language script trio spoken in brackets and NSLog.
Values
- The program shapeThe classic frame: main, an autorelease pool, and NSLog out.
- Primitives and formatsC types live alongside objects; BOOL answers YES or NO.
- NSString@"" literals are objects; messages do all the work.
Messages
- Message sendsSquare brackets everywhere — and nil quietly absorbs messages.
- SelectorsMethod names interleave with their arguments, part by part.
- alloc and initTwo-step birth: the class allocates, the instance initializes.
Classes
- @interface and @implementationThe contract and the code, declared separately.
- Properties@property writes the getter, setter and storage for you.
- The designated initializerThe init dance: call super, set up under the if, return self.
Collections
- NSArray@[] builds an array; subscripts and messages read it.
- NSDictionary@{} pairs keys with values; a miss answers nil.
- Mutable collectionsThe mutable classes subclass the immutable ones and add writers.
Enumeration
- Fast enumerationfor-in walks arrays in order and dictionaries by key.
- Block enumerationThe collection drives; your block rides along with index and stop.
- Sorting with comparatorsA block returns ascending, same, or descending; the array obeys.
Blocks
- BlocksFunction values with the famous inside-out type spelling.
- Block capturePlain captures are snapshots; __block grants write access.
- Blocks as parametersPass behavior into a function, C signature and all.
Protocols & dynamism
- ProtocolsA contract classes adopt in angle brackets.
- CategoriesAdd methods to a class you do not own — even NSString.
- Dynamic typingid holds anything; the questions get asked at run time.
C interop
- NSNumber boxing@() lifts C values into objects; unboxing is one accessor each.
- NSRange and C structsPlain C structs flow between messages and locals.
- NS_ENUMEnums with a fixed underlying type, switched exhaustively.
Encore
- word_freq.mA frequency table from a split, a counting dictionary, and one sort.
- grade_report.mReport cards from a Student class, a comparator, and format strings.
- temp_stats.mA week of temperatures: extremes, mean, a bar chart, and swings.