Skip to content

Instantly share code, notes, and snippets.

@ZalyalovIldar
Created May 31, 2020 07:32
Show Gist options
  • Save ZalyalovIldar/811decb5d28614ad4ea3d44442e0c3da to your computer and use it in GitHub Desktop.
Save ZalyalovIldar/811decb5d28614ad4ea3d44442e0c3da to your computer and use it in GitHub Desktop.
protocol CurrentUserManager {
var currentUser: User { get }
}
class CurrentUserManagerIml: CurrentUserManager {
/// Current user cached in memory
/// obtainCurrentUser - static method, obtain User model from data base/file/e.t.c.
private static var currentUser: User = obtainCurrentUser()
var currentUser: User {
return Class.currentUser
}
}
/* Usage */
class SomeClass {
lazy var currentUser: User = {
/// If you haven't Dependency Injection for class
let user = CurrentUserManagerIml().currentUser
return user
}()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment