Skip to content

Instantly share code, notes, and snippets.

@aa08666
Last active September 20, 2019 10:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aa08666/d28f43a6d2269728c1720f7bfa1d816e to your computer and use it in GitHub Desktop.
Save aa08666/d28f43a6d2269728c1720f7bfa1d816e to your computer and use it in GitHub Desktop.
Singleton

// 位置請求這種事,最好不要產出一堆實例在程式碼中,最好一次集中管理就好 class LocationManager{ // 位置請求 func requestMyLocation(){ print("TW") }

}

// 每次都要實例化一次,我覺得不行 let myLocation = LocationManager() myLocation.requestMyLocation()

class LocationManager{

static let shared = LocationManager()

init(){}

func requestMyLocation(){
    print("TW")
}

} // 實例化一次後,集中管理,我覺得可以 LocationManager.shared.requestMyLocation() //"TW"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment