Skip to content

Instantly share code, notes, and snippets.

@phucnm
Created March 9, 2019 20:17
Show Gist options
  • Save phucnm/b30fe664c1d2aa73d27208023533285c to your computer and use it in GitHub Desktop.
Save phucnm/b30fe664c1d2aa73d27208023533285c to your computer and use it in GitHub Desktop.
EnumReflection
class Analytics {
static func track(event: AppEvent) {
switch event {
case .livestreamStarted: break
// Just tracking
case .liveStreamEnded(let duration):
let param = ["duration": duration]
// Then track the event with associated param
case .gameRoomCreated(let gameName, let invitedFriends):
let param = [
"gameName": gameName,
"invitedFriends": invitedFriends
] as [String : Any]
// Then track the event with associated params
}
}
}
enum AppEvent {
case livestreamStarted
case liveStreamEnded(duration: Float)
case gameRoomCreated(gameName: String, invitedFriends: [String])
}
Analytics.track(event: .livestreamStarted)
Analytics.track(event: .liveStreamEnded(duration: 100))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment