Last active
January 5, 2018 09:25
-
-
Save vialyx/21065d7f4b245f681e6a903d9c577b6a 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
protocol AnalyticType { | |
func track(_ event: String, parameters: [String: Any]?) | |
} | |
final class FacebookAnalytic: AnalyticType { | |
func track(_ event: String, parameters: [String : Any]?) { | |
// TODO: - Send facebook event | |
} | |
} | |
final class GoogleAnalytic: AnalyticType { | |
func track(_ event: String, parameters: [String : Any]?) { | |
// TODO: - Send Google event | |
} | |
} | |
final class AnalyticService: AnalyticType { | |
let interactors: [AnalyticType] | |
init(interactors: [AnalyticType]) { | |
self.interactors = interactors | |
} | |
func track(_ event: String, parameters: [String : Any]? = nil) { | |
interactors.forEach { $0.track(event, parameters: parameters) } | |
} | |
} | |
let facebookInteractor = FacebookAnalytic() | |
let googleInteractor = GoogleAnalytic() | |
let analyticService = AnalyticService(interactors: [facebookInteractor, googleInteractor]) | |
analyticService.track("Login") | |
analyticService.track("Post a story", parameters: ["title": "SOLID in swift"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment