This is probably historical. Objective-C supports strong typing, but also supports duck typing, in which you donβt care which class the object is, you care about what messages it responds to (i.e. if it looks like a duck and it bows like duck, it's probably a duck). You are allowed to enter each object pointer as id and send any messages. Indeed, the recipient does not need to implement methods for any message that he receives anyway: he can simply redirect the message to another object.
In the Application Kit - the previous GUI for OpenStep and Cocoa - almost all objects were used with duck printing. Here's the (partial) interface for Window from version 3.2 of the Application Kit.
@interface Window : Responder { NXRect frame; id contentView; id delegate; id firstResponder; id lastLeftHit; id lastRightHit; id counterpart; id fieldEditor; int winEventMask; int windowNum; float backgroundGray;
Note that the contentView ivar is defined as id and that all types in access methods are implicitly defined as id too (therefore, -setContentView: returns an object: possibly a Window instance of self ). What Objective-C code looked like in the early 1990s: The Application Kit was probably the most Objective-C code in the early 1990s.
NSWindow was introduced in the first version of AppKit - the GUI in what Cocoa became in 1994. AppKit typically uses more stringent type declarations than the Application Kit, but this is not strictly enforced. In fact, it may even be that AppKit NSWindow contains code from the Application Kit Window and that this contentView contentView has not been updated in a change.
Indeed, the stringent requirement of type matching in Objective-C variables is relatively small. Most of the rigor was introduced either through property declarations (which are strongly typed, except that C exists and supports casting), or by changing protocols that allow optional methods, which allows you to strictly type delegate objects.
user23743
source share