Created
May 5, 2020 03:14
-
-
Save TungVuDuc2805/580e797c20490bbfd8455c7d6591f98a to your computer and use it in GitHub Desktop.
This file contains 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
class CompositeStrategy : Strategy { | |
let wifiLoader: WifiLoader | |
let cellularLoader: CellularLoader | |
let localLoader: LocalLoader | |
init(wifiLoader: WifiLoader, cellularLoader: CellularLoader, localLoader: LocalLoader){ | |
self.wifiLoader = wifiLoader | |
self.cellularLoader = cellularLoader | |
self.localLoader = localLoader | |
} | |
func load(completion: @escaping (Result<[FeedItem], Error>) { | |
var loader: Loader? | |
if Reachability.isWifi { | |
loader = wifiLoader | |
} else if Reachability.isCelluar { | |
loader = cellularLoader | |
} else if Reachability.isOffline { | |
loader = localLoader | |
} | |
loader?.load(completion: completion) | |
... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment