Created
March 9, 2019 20:17
-
-
Save phucnm/b30fe664c1d2aa73d27208023533285c to your computer and use it in GitHub Desktop.
EnumReflection
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 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