Skip to content

Instantly share code, notes, and snippets.

@willie-hung
Created September 25, 2023 20:53
Show Gist options
  • Save willie-hung/292516186e110343b43d180c37f71cc7 to your computer and use it in GitHub Desktop.
Save willie-hung/292516186e110343b43d180c37f71cc7 to your computer and use it in GitHub Desktop.
 iOS Interview Prep 4- Singleton pattern
class DatabaseManager {
static let databaseObj = DatabaseManager()
private init() {
}
func checkDatabaseAccess(user: String) {
if user == ("Sung-Jie") {
print("Access Granted!")
} else {
print("Access Denied!")
}
}
}
let userName = "Sung-Jie"
let database = DatabaseManager.databaseObj
database.checkDatabaseAccess(user: userName)
// Console output:
// Access Granted!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment