Browse Questions
  • A memory leak is memory that is allocated but never freed — usually from retain cycles.
  • Tasks support cooperative cancellation — you cancel from outside, and the task must check for cancellation and stop itself.
  • A lazy property is only computed the first time it is accessed.
  • An Xcode MVP Feature template generates four pre-wired files for UIKit screens (Contract, Presenter, View, and ViewController) using protocol abstractions and @MainActor isolation to maintain…

Answer: A lazy property is only computed the first time it is accessed. Useful for expensive operations you may not always need.

Code Example:

class DataProcessor {
    // Only created when first accessed
    lazy var expensiveData: [String] = {
        print("Computing...")
        return loadFromDisk() // expensive operation
    }()
}

let processor = DataProcessor()
// expensiveData not computed yet
let data = processor.expensiveData // computed now, cached after
let again = processor.expensiveData // returned from cache, no recompute

Key Points:

  • Must be var, not let
  • Not thread-safe by default — use care in concurrent contexts
  • Great for views, formatters, and other setup-heavy properties