Last active
August 29, 2015 14:06
-
-
Save krzyzanowskim/1b0c957fe112a61760ea to your computer and use it in GitHub Desktop.
How to use class constant to initialize variable - solution is use lazy variable
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
import Foundation | |
class Foo { | |
let length = 255 | |
// !!! not like this because self.length can't be used here | |
// var arrayConstantLength = [Byte](count:self.length, repeatedValue:0) | |
// but like this (with lazy I can use self.length constant) | |
lazy var arrayConstantLength:[Byte] = { | |
[unowned self] in return [Byte](count: self.length, repeatedValue: 0) | |
}() | |
} | |
let q = Foo().arrayConstantLength |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment