1

I am using cocoa-pod for Google Analytics.

Pod file

source 'https://github.com/CocoaPods/Specs.git'

target 'MyProject' do
    pod 'FBSDKCoreKit'
    pod 'FBSDKShareKit'
    pod 'FBSDKLoginKit'
    pod 'GoogleAnalytics'
end

Bridging header

#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKLoginKit/FBSDKLoginKit.h>
#import <FBSDKShareKit/FBSDKShareKit.h>
#import "GAI.h"
#import "GAIFields.h"
#import "GAIDictionaryBuilder.h"

Everything's work fine but after adding GoogleAnalytics into my pod Xcode detect some error which should not be.

func design(invitationInfo object: AnyObject) {
    eventId = object["eventId"] as? String
    message = object["message"] as? String
    location = object["location"] as? String
}

In the above area Xcode ask to unwrap all the values.

enter image description here

I am not able to understand what to do. Cause I can not give guarantee that those values will come as string.

Tapas Pal
  • 7,073
  • 8
  • 39
  • 86

2 Answers2

0

I had the same problem after installing GoogleAnalytics with cocoapods. I don't know where this error come from but you can try this to guarantee object's values are String:

func design(invitationInfo object: AnyObject) {
    if object["eventId"] is String {
        eventId = object["eventId"] as! String
    }
    if object["message"] is String {
        message = object["message"] as! String
    }
    if object["location"] is String {
        location = object["location"] as! String
    }
}
Bogy
  • 944
  • 14
  • 30
  • Yes we can do. But this is not the optimal solution. I just illustrate the problem by one method. There total 286 error caught. If I really need to do that you suggested, will be very hectic. – Tapas Pal Jun 13 '16 at 12:05
  • You right, probably not the right solution for 286 errors... You can try to import Google Analytics like this `#import ` maybe a piece of code is missing in the way you are importing it. You can also try to clean your project (Shift+cmd+K), it works like magic some times ^^ – Bogy Jun 13 '16 at 12:19
-1

As error Says You have to use '!' ,

Try Below code,

let eventID: String? = object["eventID"]

After creating eventID you need to check it for nil before using it.

Mtoklitz113
  • 3,828
  • 3
  • 21
  • 40