In Swift, it seems that global constants should be camelCase.
For example:
let maximumNumberOfLoginAttempts = 10
Is that correct?
I'm used to all caps, e.g., MAXIMUM_NUMBER_OF_LOGIN_ATTEMPTS
, from C, but I want to acquiesce to Swift conventions.
In Swift, constants are declared using the let keyword. In a similar fashion to variables, the let keyword is followed by the name of the constant you want to declare and then a type annotation (a colon, a space and then the type of data you want to store in the constant).
Constants should be written in uppercase characters separated by underscores. Constant names may also contain digits if appropriate, but not as the first character.
The names of variables declared class constants and of ANSI constants should be all uppercase with words separated by underscores ("_"). (ANSI constants should be avoided, for ease of debugging.)
Swift 3 API guidelines state that "Names of types and protocols are UpperCamelCase. Everything else is lowerCamelCase."
https://swift.org/documentation/api-design-guidelines/
Ideally your global constants will be located within a struct of some sort, which would be UpperCamelCase, and all properties in that struct would be lowerCamelCase
struct LoginConstants { static let maxAttempts = 10 }
And accessed like so,
if attempts > LoginConstants.maxAttempts { ...}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With