I would like to implement a lazy property so that it will not have a value until it is accessed for the first time. But then later I want to set it to nil to free up memory resources. Then when the app tries to access it again, it will be recreated, therefore it shouldn't ever be nil when it's about to be accessed.
I looked through the Swift Programming book and read up on lazy properties, but the information there is sparse, there was no example of this use case.
I saw this answer by Rudolf Adamkovic and implemented that format, but the project won't compile in Xcode 6.2 beta 3: Use of undeclared type 'String'
let model = MyModelClass()
lazy var recentlyAdded: [String] = self.recents() //error here
func recents() -> [String] {
return self.model.recentlyAdded()
}
I also tried this format, but it too fails to compile with the same compile-time error.
lazy var recentlyAdded: [String] = self.model.recentlyAdded()
What is the proper way to implement this type of lazy property?