ref – http://mikebuss.com/2014/06/22/lazy-initialization-swift/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
class Node { lazy var players: [String] = { var temporaryPlayers = [String]() temporaryPlayers.append("John Doe") return temporaryPlayers }() lazy var people: [String] = self.initialPeople() private func initialPeople() -> [String] { let people = ["Ricky T", "John D", "walter"] return people } } print("---- \(#function) ------") var myNode = Node() print(myNode.players) print(myNode.people) |