-
Notifications
You must be signed in to change notification settings - Fork 79
/
LazyProperty.swift
25 lines (22 loc) · 844 Bytes
/
LazyProperty.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
/*
A lazy stored property is a property whose initial value is not calculated
until the first time it is used. You indicate a lazy stored property by writing
the lazy modifier before its declaration.
*/
class DataImporter {
/*
DataImporter is a class to import data from an external file.
The class is assumed to take a nontrivial amount of time to initialize.
*/
var filename = "data.txt"
// the DataImporter class would provide data importing functionality here
}
class DataManager {
lazy var importer = DataImporter()
var data = [String]()
// the DataManager class would provide data management functionality here
}
let manager = DataManager()
manager.data.append("Some data")
manager.data.append("Some more data")
// the DataImporter instance for the importer property has not yet been created