December 2018
Intermediate to advanced
414 pages
10h 19m
English
First, you'll need to define a common protocol or interface that all your objects share. This will ensure all of our adapters share the same interface.
In this particular scenario, we simply want to track events with additional and optional custom properties. It can be defined as follows:
public protocol Tracking { func record(event: String) func record(event: String, properties: [String: String]?)}
Thanks to protocol extensions, it is also possible to define the default implementation of tracking with empty properties:
extension Tracking { func record(event: String) { record(event: event, properties: nil) }}
Now that the base tracking protocol is defined, it is possible to expose the shared tracker:
public class Tracker: Tracking ...
Read now
Unlock full access