Skip to content

Instantly share code, notes, and snippets.

@vialyx
Last active January 5, 2018 09:25
Show Gist options
  • Save vialyx/21065d7f4b245f681e6a903d9c577b6a to your computer and use it in GitHub Desktop.
Save vialyx/21065d7f4b245f681e6a903d9c577b6a to your computer and use it in GitHub Desktop.
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