Search code examples
objective-cswiftscenekitarkit

Global and local argument names in renderer(_:didAdd:for:) method


We always use local parameter names (node and anchor) in SceneKit methods like:

optional func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor)

In which case the global argument names didAdd and for can be used?


Solution

  • This pattern follows the Swift API Design Guidelines:

    More words may be needed to clarify intent or disambiguate meaning, but those that are redundant with information the reader already possesses should be omitted. In particular, omit words that merely repeat type information.

    While the Objective-C API is:

    - (void)renderer:(id<SCNSceneRenderer>)renderer 
          didAddNode:(SCNNode *)node 
           forAnchor:(ARAnchor *)anchor;
    

    It is translated into Swift as:

    optional func renderer(_ renderer: SCNSceneRenderer, 
                    didAdd node: SCNNode, 
                       for anchor: ARAnchor)
    

    Presumably the caller knows the types of the arguments so the type information was omitted.

    This is also the way Objective-C methods are automatically translated into Swift; see Name Translation from C to Swift and Omit-needless-words.