Skip to content

Instantly share code, notes, and snippets.

@samuelbeek
Last active October 21, 2015 18:55
Show Gist options
  • Save samuelbeek/16545b375b43396d885e to your computer and use it in GitHub Desktop.
Save samuelbeek/16545b375b43396d885e to your computer and use it in GitHub Desktop.
Constants in Swift
// My way of doing constants in Swift.
// Usage example: if(Constants.debug) { println("debug message") }
struct Constants {
// App wide things:
static let debug = true
static let production = true
static let appVersion = "iOS-0.1.0b300"
static let apiBase = "http://api.com/1"
// Subgroups:
struct Colors {
static let blue = UIColor.fromRGB(0x7AA1BE)
static let green = UIColor.fromRGB(0x6EBE78)
static let red = UIColor.fromRGB(0xEA4240)
}
struct Devices {
static let iPhone4 = UIScreen.mainScreen().scale == 2.0 && UIScreen.mainScreen().bounds.size.height == 480.0
static let iPhone5 = UIScreen.mainScreen().scale == 2.0 && UIScreen.mainScreen().bounds.size.height == 568.0
static let iPhone6 = UIScreen.mainScreen().scale == 2.0 && UIScreen.mainScreen().bounds.size.height == 667.0
static let iPhone6plus = UIScreen.mainScreen().scale == 3.0 && UIScreen.mainScreen().bounds.size.height == 736.0
}
struct Placeholders {
static let namePlaceholder = "What's your name?"!
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment