Possibly I'm mistunderstanding you, but are you looking for something like the following?
class Foo {
let Key1 = "Key1"
let Key2 = "Key2"
lazy var tutorial : [String] = { [self.Key1, self.Key2] }()
/* Alternatively:
lazy var tutorial : [String] = [self.Key1, self.Key2] */
init() {}
}
Note that I'm accessing the same-class properties using prefix .self
.
Alternatively, just use a computed property. In the simple example above, Key1
and Key2
are immutables, so it's really no reason to let tutorial be a lazy, stored property:
class Foo {
let Key1 = "Key1"
let Key2 = "Key2"
/* now as a computed property: */
var tutorial : [String] { return [Key1, Key2] }
init() {}
}
If Key1
and Key2
were mutables, however, then the two solutions above would differ:
lazy var tutorial
would be lazily initialized (upon first use) with the current values of Key1
and Key2
, at that time, but not be influenced by later changes in Key1
and/or Key2
.
- Letting
tutorial
be a computed property, however, would always yield an (computed) array the current values of Key1
and/or Key2
.
Edit addition (after edited question):
For the updated example in your question, the the lazy variable is used just in the same way as described above:
class TestViewController: UIViewController {
let Key1 = "Key1"
let Key2 = "Key2"
lazy var tutorial : [String] = [self.Key1, self.Key2]
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}