swiftmethodsmethod-names

Naming methods in Swift versus Objective-C


All:

In Objective-C, the name is constructed by concatenating the signature keywords, e.g., application:didFinishLaunchingWithOptions:

How do people refer to the equivalent method in Swift, when discussing it with other programmers (including students)? For example, would you refer to verbally as application(), or application(_ didFinishLaunchingWithOptions:)?

Thanks,

Michael


Solution

  • Apple's style is to include all the parts of the declaration that make its unique function signature (and omit things that matter only to the implementor, like local parameter names). If you set the view on one of Apple's reference pages to Swift-only, you'll see this style in the method listings:

    application(_:willFinishLaunchingWithOptions:)
    application(_:didFinishLaunchingWithOptions:)
    applicationDidBecomeActive(_:)
    applicationWillResignActive(_:)
    

    Obviously, when speaking aloud one can omit the punctuation and people will still know what you're talking about.

    (Notice you can't call either of the first two just application(), because there are two distinct methods with that base name and different external parameter labels.)