0
votes

I'm following the instructions on here to integrate google analytics into my app: https://developers.google.com/analytics/devguides/collection/ios/v3/?ver=swift#get-config

I'm at the point where I need to initialize analytics for my app. I've added this code in my AppDelegate.swift file:

import UIKit
import <Google/Analytics.h>

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDelegate {

    var window: UIWindow?


    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions:[NSObject: AnyObject]?) -> Bool {
        **// Configure tracker from GoogleService-Info.plist.
        NSError *configureError;
        [[GGLContext sharedInstance] configureWithError:&configureError];
        NSAssert(!configureError, @"Error configuring Google services: %@", configureError);

        // Optional: configure GAI options.
        GAI *gai = [GAI sharedInstance];
        gai.trackUncaughtExceptions = YES;  // report uncaught exceptions
        gai.logger.logLevel = kGAILogLevelVerbose;  // remove before app release**

    }

I'm getting the following error messages.

  1. For my import <Google/Analytics.h> line, I'm getting this message:'Consecutive statements on a line must be separated by ';'.

  2. For the rest of the code I'm getting several errors, although I simply copied the code in the tutorial into my file. See my screenshot.

enter image description here

1
You can't put objective-c code in your swift file - dan

1 Answers

0
votes

You're getting this issue since you're in a Swift project. You'll need to create an Objective-C bridging header, and add the import statement there. Afterwards, everything should work properly. Check out this SO answer for more details:

https://stackoverflow.com/a/24005242/1784384