Global Variables

// excerpted from Swift Tutorials
var landmarks: [Landmark] = load("landmarkData.json")

// excerpted from 彼得潘
var grade = 0
  • 任何檔案皆可存取 global variable。

  • global variable 寫在哪個檔案都可以。

  • Global constants and variables are always computed lazily.

    👉 Lazy Stored Properties

  • Global variables are defined outside of any function, method, closure, or type context.

Last updated

Was this helpful?