Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift naming conventions for booleans, constants and @IBAction selectors?

I have been reading the API Design Guidelines for Swift and some posts regarding naming those entities I said in the title of the question, but I am still not clear about that.

I am developing in Swift 3.

  1. Boolean variables should be prefixed with is-, with has-, or both prefixes are appropriate?
  2. Methods returning Bool selectors should also be prefixed is/has?
  3. Constant variables that, for example, you define to avoid magic numbers, should start with a k? (for example, kMaxLength). I think this was a convention for Objective-C, is it for Swift as well?
  4. The name for an @IBAction selector, should refer to the control that triggers the action, or the task it does? (For example: doneButtonTapped vs validateInput)
like image 978
AppsDev Avatar asked Dec 07 '16 13:12

AppsDev


1 Answers

Swift general naming conventions are available here https://swift.org/documentation/api-design-guidelines/#general-conventions

  • Uses of Boolean methods and properties should read as assertions about the receiver when the use is nonmutating, e.g. x.isEmpty, line1.intersects(line2).
  • The names of other types, properties, variables, and constants should read as nouns.
like image 99
Niko Avatar answered Sep 30 '22 05:09

Niko