typestar

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.

Start this tour

Values

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

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

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

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.

The other Objective-C tours