Wrapping Third-Party SDKs with Property Wrappers

Jonathan Wong
Oct 24, 2020

Property wrappers have been out since Swift 5.1, but I haven’t thought
of a use case to create my own, until now.

In full disclosure, I currently work at Tealium where we build SDKs to
help collect data, but more importantly, connect data.
All thoughts are
my own.

Autotracking

When it comes to analytic SDKs, or SDKs in the marketing technology
space, people often ask about autotracking. What is autotracking? It’s the concept of not having to track any events yourself as the user of the SDK. Instead, you rely on the SDK to automatically track events on your behalf.

Now while this sounds like a handy feature, it only takes you so far. When it comes to logging a purchase or something that requires actual data from your app, most of these autotracking solutions do not provide much value. It just saves you from writing something like the following in viewDidLoad:

Analytics.shared.logScreenView("Home")

Furthermore, if you think about how to achieve autotracking, one way to do it is to leverage Objective-C’s flexible runtime and implement some good old-fashioned method swizzling.

Because autotracking and method swizzling often have negative connotations around them, most MarTech SDKs have a way to disable this feature and allow manually tracking your app’s screen views yourself. Let’s see how we can get the best of both worlds with wrapping a third-party SDK with property wrappers.

Enter Property Wrappers

The rest of this article can be seen on my own site:

Wrapping Third-Party SDKs with Property Wrappers

--

--

Jonathan Wong

Cook, eat, run… San Diego Software Engineer, Pluralsight Author, RW Team Member