Daily iOS
Architecture

Analytics event dispatch

This is a take-home assignment. Design a layer in plain Swift that sends analytics events to several services (Google Analytics, Snowplow, and so on). Requirements: one line at the call site, events are modular and easy to add or remove, event names and parameters can differ per service, a service can opt in to specific events, and adding a service touches no existing code. How do you design the types?

How would an interviewer hear this answer? You'll see whether they'd move on, dig in, or say no, and which sentences would trip you up. Your score doesn't change.
See the short answer

Abstract events as an AnalyticsEvent protocol (or enum) and services as an AnalyticsService protocol, and have a dispatcher fan out events to the registered services. Each service maps an event to its own name and parameters and opts in through supports(event).

Share a question