Contact Us

Use the form on the right to contact us.

You can edit the text in this area, and change where the contact form on the right submits to, by entering edit mode using the modes on the bottom right. 


Oak Ridge, TN, 37830
United States

Swift-Snips

Cannot Convert value of type ... to type '[ANyHashable : Any]' in Coercion

Wade Cantley

The ongoing effort to convert my app after an upgrade to XCode 8 and Swift 3.

Just when I thought I was error free, a new set of errors popped up and this is one that is pretty frequent.

I have already run the Swift 3.0 update on the code so this is part of the group of errors that are remaining.  

Here is a link to where I found the answer.

 

http://stackoverflow.com/questions/39630247/swift-3-cannot-convert-value-of-type-nsmutabledictionary-to-expected-argument

The gist is that using "AnyHashable: Any" just doesn't like a dictionary to be mutable.  So I changed the target code to look like this. 

From 

        // [START GOOGLE ANALYTICS]
        let tracker = GAI.sharedInstance().defaultTracker
        tracker?.set(kGAIScreenName, value: storyboardViewName)
        let builder = GAIDictionaryBuilder.createScreenView()
        tracker?.send(builder?.build() as [AnyHashable: Any])
        // [END GOOGLE ANALYTICS]

To

        // [START GOOGLE ANALYTICS]
        let tracker = GAI.sharedInstance().defaultTracker
        tracker?.set(kGAIScreenName, value: storyboardViewName)
        let builder = GAIDictionaryBuilder.createScreenView()
        tracker?.send(builder?.build() as NSDictionary? as? [AnyHashable: Any] ?? [:])
        // [END GOOGLE ANALYTICS]

This seems to have solved the issue.