Matthew Bradshaw Matthew Bradshaw - 1 year ago 260
Swift Question

Use of unresolved identifier GGLContext and GAI

I am having a bit of trouble. I am attempting to install Google Analytics into an app and am consistently getting the use of unresolved identifier

error. I receive the same error whether I am using CocoaPods or not. The location of the error is in the

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.

var configureError:NSError?
assert(configureError == nil, "Error configuring Google services: \(configureError)")

// Optional: configure GAI options.
let gai = GAI.sharedInstance()
gai.trackUncaughtExceptions = true // report uncaught exceptions

return true

Nothing additional is able to be imported into the
(such as Google), just the standard

I have been through many tutorials and other SO questions, all to no avail. I figure that there is some small thing I am missing, but cannot find it.

What I've done:

I have the
files in my project, along with
(all of which have been linked to library as well as CoreData and SystemConfiguration).

You can see the layout of all these files here:

enter image description here

and here:

enter image description here

I have created the
and included these
imports in it.

#import "GAI.h"
#import "GAIDictionaryBuilder.h"
#import "GAIEcommerceFields.h"
#import "GAIEcommerceProduct.h"
#import "GAIEcommerceProductAction.h"
#import "GAIEcommercePromotion.h"
#import "GAIFields.h"
#import "GAILogger.h"
#import "GAITrackedViewController.h"
#import "GAITracker.h"

is linked in the Build Settings and I receive no errors with that. That is the main solution that I have found during my research, which hasn't helped me in this situation.

I have tried to start over from scratch twice with CocoaPods and without (I made a copy of my project before starting) and I received the same error each time.

Any help would certainly be appreciated. Thanks in advance.

Answer Source

Well, it looks like I was able to get it squared away.

There were several problems with all attempts on this.

  1. Cocoapods had not installed correctly. I reinstalled and then had better success importing the correct files.

  2. Doing it manually, as I posted above is not the best option.

  3. After the Cocoapods re-install and starting over from a fresh copy of my project, I was able to import Google into my AppDelegate.swift.

Key points for those who may end up in the same boat I was in:

  • Be sure to add the correct directory for your -Bridging-Header.h. You can find this under Project - Build Settings - Swift Compiler Code Generation. Use this to easily target your header file $(SWIFT_MODULE_NAME)-Bridging-Header.h

  • In your -Bridging-Header.h, do not #import <Google/Analytics.h>, instead import the files individually. Here is an image of the files available to be imported.

enter image description here

  • When in doubt, reinstall Cocoapods

  • Do not trust Google tutorials to provide the most effective instruction and utilize the many SO posts on the topic.

I really hope this helps someone not spend 10 hours on the problem as I have.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download