December 2018
Intermediate to advanced
414 pages
10h 19m
English
The adapter pattern makes use of classes to wrap the functionality of immutable interfaces, such as the two libraries we are using:
public class MixPanelTrackingAdapter: Tracking {
Wrap the Mixpanel mainInstance, as follows:
private let mixpanel = Mixpanel.mainInstance()
Next, expose the required methods from the Tracking protocol:
public func record(event: String, properties: [String : String]?) { mixpanel.track(event: event, properties: properties) }}
For Google Analytics for Firebase, it's even more trivial, as there is no singleton to wrap:
public class FirebaseTrackingAdapter: Tracking { public func record(event: String, properties: [String : String]?) { Analytics.logEvent(event, parameters: properties) } ...Read now
Unlock full access