Swift: Global constant naming convention?

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 an enum, extension, or struct of some sort, which would be UpperCamelCase, and all properties in that space would be lowerCamelCase.

struct LoginConstants {
    static let maxAttempts = 10
}

And accessed like so,

if attempts > LoginConstants.maxAttempts { ...}

(credit to Ryan Maloney’s answer for calling out the benefits of enum)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)