To improve on bmjohns answer, it's better to use an enum
instead of a struct
to act as a namespace for your constants. An enum
with no cases can't be instantiated, whereas a struct
can. If it is a struct
, then instantiating it (via LoginConstants()
) is allowed, but that has no meaning and doesn't make sense to do.
The convention is to use enumerations for namespacing, as such:
enum LoginConstants {
static let maxAttempts = 10
}
This ensures that the only valid usage of LoginConstants
is for accessing its static members.