Reputation: 3955
After following the overview found here:
https://developers.google.com/analytics/devguides/collection/ios/v2/
I am seeing an Unused variable "tracker"
warning on the last line of the code added to:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
Here's the code from Google's overview page:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Optional: automatically track uncaught exceptions with Google Analytics.
[GAI sharedInstance].trackUncaughtExceptions = YES;
// Optional: set Google Analytics dispatch interval to e.g. 20 seconds.
[GAI sharedInstance].dispatchInterval = 20;
// Optional: set debug to YES for extra debugging information.
[GAI sharedInstance].debug = YES;
// Create tracker instance.
id<GAITracker> tracker = [[GAI sharedInstance] trackerWithTrackingId:@"UA-YOUR-TRACKING-ID"];
}
tracker
truly sees absolutely no use past this point and the overview document doesn't really say what to do with it. Any suggestions?
Upvotes: 14
Views: 4163
Reputation: 9911
If you don't need a reference to your tracker (and it looks like you don't) you can remove the warning by changing the last line of code from
id<GAITracker> tracker = [[GAI sharedInstance] trackerWithTrackingId:@"UA-YOUR-TRACKING-ID"];
to
[[GAI sharedInstance] trackerWithTrackingId:@"UA-YOUR-TRACKING-ID"];
A use case for keeping a reference to the tracker in this block of code could be if you wanted to create an event for when a user starts the application, without having to call [GAI sharedInstance]
to get that reference.
Upvotes: 24