Overuse of lazy vars?

Hello, I’m browsing through the book to learn core data and so far so good. Great job!

However, one question I cannot help myself asking is Why are you guys using lazy vars all over the place ?

I understand one of the main benefits of lazy vars is to defer potentially expensive operations, and that sometimes they are unavoidable like when setting up the core data stack, but is this pattern necessary for predicates for instance ?

For instance in Chap04:
lazy var cheapVenuePredicate: NSPredicate = { var predicate = NSPredicate(format: "priceInfo.priceCategory == %@", "$") return predicate }()

what’s the benefit vs a good old:
let cheapVenuePredicate = NSPredicate(format: "priceInfo.priceCategory == %@", "$")

The idea is to improve the memory load of the app by keeping that predicate out of memory until you need it. Lazy properties are 'var’s and are usually computed properties that only get calculated right when they get accessed the first time.

Thanks for your answer, but I’m not sold on the idea of improving the memory load: as an object, a predicate will indeed take more memory than a primitive data type like an Int or a String, but not that much (I think), and in the context of a class, viewController or whole app, that shouldn’t make any difference at all.

But again, I’m new to CoreData so maybe I’m missing something ? Any links that show that predicates are memory hogs maybe or that defining predicates with lazy vars is an improvement over standard vars ?

Cheers

PS: Also, what is the point of doing something like the following in the app delegate ? :

lazy var coreDataStack = CoreDataStack()

fun application(_:didFinishLauchingWithOptions:) → Bool {
// omitted code
someViewController.coreDataStack = coreDataStack
}

Trying to answer your question within the Post Scriptum. We are creating an instance of the CoreDataStack class, and then we pass it to the ViewController so that it can use its managed object context to fetch/save data into Core Data.