Last active
August 29, 2015 14:20
-
-
Save gfontenot/19924dace096e89ceed1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// stored property, no default value | |
let foo: String | |
// stored property, default value | |
let foo: String = "foo" | |
// or | |
let foo = "foo" | |
// computed property, no custom setter | |
var foo: String { | |
// access to other instance properties in here | |
return "foo" | |
} | |
// computer property, custom setter and getter | |
var foo: String { | |
get { return "foo" } | |
set { /* do some stuff with `newValue` */ } | |
} | |
// stored property, default value provided by an immediately executed closure | |
let foo: String = { | |
// no access to instance properties in here | |
return "foo" | |
}() | |
struct Foo { | |
static let foo: String = Foo.baz() // this works | |
let bar: String = quz() // this doesn't, expects to be passed an instance | |
static func baz() -> String { | |
return "" | |
} | |
func quz() -> String { | |
return "" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment