11.7 Name scope and Identifiers

In Object Pascal, each identifier must be unique in its namespace: the unit. In Objective-C, this need not be the case and each type identifier must be unique among its kind: classes, protocols, categories, fields or methods. This is shown in the definitions of the basic protocol and class of Objective-C: Both protocol and class are called NSObject.

When importing Objective-C classes and protocols, the Objective-Pascal names of these types must conform to the Object Pascal rules, and therefore must have distinct names. Likewise, names that are valid identifiers in Objective-C may be reserved words in Object Pascal. They also must be renamed when imported.

To make this possible, the External and “message” modifiers allow to specify a name: this is the name of the type or method as it exists in Objective-C:

NSObjectProtocol = objcprotocol external name 'NSObject'  
  function _class: pobjc_class; message name 'class';  
end;  
 
NSObject = objcclass external (NSObjectProtocol)  
  function _class: pobjc_class;  
  class function classClass: pobjc_class; message 'class';  
end;