Skip to content

Instantly share code, notes, and snippets.

@andr-ec
Created November 28, 2020 22:48
Show Gist options
  • Save andr-ec/8514cbef34a575e8ad525ee4ac1884ce to your computer and use it in GitHub Desktop.
Save andr-ec/8514cbef34a575e8ad525ee4ac1884ce to your computer and use it in GitHub Desktop.
Protocol
struct UserData {
}
protocol UserServiceProtocol {
var user: UserData? { get set }
func load()
}
class UserGraphQLService: UserServiceProtocol {
var user: UserData? = nil
func load() {
// async load from disk.
self.user = UserData()
}
}
class UserDiskService: UserServiceProtocol {
var user: UserData? = nil
func load() {
// async load from graphql endpoint.
self.user = UserData()
}
}
class SomeViewController: UIViewController {
var userService: UserServiceProtocol
init(userService: UserServiceProtocol) {
self.userService = userService
super.init(nibName: nil, bundle: nil)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
super.viewDidLoad()
userService.load()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment