Skip to content

Commit

Permalink
Update Constants section for Swift
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Richter committed Aug 6, 2015
1 parent 9f1137e commit bcc40ea
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,23 @@ Find more information about localization in [these presentation slides][l10n-sli

#### Constants

Keep app-wide constants in a `Constants.h` file that is included in the prefix header.
In Swift, you can use structs defined in a `Constants.swift` file to group, store and access your app-wide constants in a clean way:

```swift

struct Config {
static let baseURL: NSURL(string: "http://www.example.org/")!
static let splineReticulatorName = "foobar"
}

struct Color {
static let primaryColor = UIColor(red: 0.22, green: 0.58, blue: 0.29, alpha: 1.0)
static let secondaryColor = UIColor.lightGrayColor()
}

```

When using Objective-C, keep app-wide constants in a `Constants.h` file that is included in the prefix header.

Instead of preprocessor macro definitions (via `#define`), use actual constants:

Expand Down

0 comments on commit bcc40ea

Please sign in to comment.