jeudi 15 décembre 2016

Add analytics event to each ViewController in the project with its name

I have a project in which I need to log an analytics event whenever any View Controller (log the name of the View Controller) comes on screen.

I was trying to avoid littering all of my existing View Controller classes with call to the analytics SDK.

I tried making an AnalyticsViewController and all my View Controllers would subclass this View Controller, and then I add analytics event in AnalyticsViewController class's viewDidLoad method. But the problem with this approach is that AnalyticsViewController does not which child View Controller is the call coming from.

I am using Swift 3.0. I believe that Swift with its powerful language features should be able provide me with an abstraction of some sorts.

Is there any way through this problem without littering all the View Controllers?

Aucun commentaire:

Enregistrer un commentaire