Created
November 28, 2020 22:48
-
-
Save andr-ec/8514cbef34a575e8ad525ee4ac1884ce to your computer and use it in GitHub Desktop.
Protocol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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