Skip to content

Instantly share code, notes, and snippets.

@leoneparise
Last active April 4, 2017 19:49
Show Gist options
  • Save leoneparise/4ed6fa09968e5a5b56ae95d0c00e6c21 to your computer and use it in GitHub Desktop.
Save leoneparise/4ed6fa09968e5a5b56ae95d0c00e6c21 to your computer and use it in GitHub Desktop.
//: Playground - noun: a place where people can play
import Foundation
protocol EventType {
var name: String { get }
var info: [ String : Any ] { get }
}
protocol TimedEventType {
var name: String { get }
var category: String { get }
var interval: TimeInterval { get }
}
class Event: EventType {
let name: String
let info: [ String : Any ]
init(_ name:String, _ info: [ String : Any ]) {
self.name = name
self.info = info
}
}
class TimedEvent: TimedEventType {
let name: String
let category: String
let interval: TimeInterval
init(_ name:String, _ category: String, _ interval: TimeInterval) {
self.name = name
self.category = category
self.interval = interval
}
}
enum SBTEvents {
class action1: Event {
init(param:String) {
super.init("Action 1", [ "param" : param ])
}
}
class action2: TimedEvent {
init(interval:TimeInterval) {
super.init("Action 1", "Some Category", interval)
}
}
}
class Analytics {
private static var shareInstance:Analytics!
static var shared:Analytics {
if shareInstance == nil {
shareInstance = Analytics()
}
return shareInstance
}
private init() {
/* Initialize some analytics implementations */
}
func log(event:EventType) {
print("\(event.name) \(event.info)")
}
func log(event:TimedEventType) {
print("\(event.name) \(event.category) \(event.interval)")
}
func log(screen:String) {
print(screen)
}
}
Analytics.shared.log(event: SBTEvents.action1(param: "Some value"))
Analytics.shared.log(event: SBTEvents.action2(interval: 2.0))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment