Skip to content

Instantly share code, notes, and snippets.

@kuyazee
Last active June 27, 2018 14:36
Show Gist options
  • Save kuyazee/50c7ea0abc29d9e9a869d1373600d96d to your computer and use it in GitHub Desktop.
Save kuyazee/50c7ea0abc29d9e9a869d1373600d96d to your computer and use it in GitHub Desktop.
public enum AnalyticsEvent: AnalyticsEventProtocol {
case userLoggedIn
case userLoggedOut
case productSelected(productId: Int)
var name: String {
switch self {
case .userLoggedIn: return "User Logged In"
case .userLoggedOut: return "User Logged Out"
case .productSelected: return "Product Selected"
}
}
/// The parameters before used the AnalyticsEventProtocol's default implementation which
/// always returned nil. Now we just have to create our own implementation based on the
/// cases of this enum.
var parameters: [String: Any]? {
switch self {
case .userLoggedIn: return nil
case .userLoggedOut: return nil
case .productSelected(id: let id): return ["product_id": productId]
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment