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

Filtering by Category: Troubleshooting

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.

Use Legacy Language Version

Wade Cantley

“Use Legacy Swift Language Version” (SWIFT_VERSION) is required to be configured correctly for targets which use Swift. Use the [Edit > Convert > To Current Swift Syntax…] menu to choose a Swift version or use the Build Settings editor to configure the build setting directly.

What's going on?

This relates to an imported framework, in this situation it is HanekeSwift, and it would appear there is a version dependency difference that doesn't quite match up.

That said, the app has been updated to Swift 3.0 and it would appear that the app is only compatible with 2.3. 

As always, it is best to look at whether others have addressed the issue and in this situation it looks like someone has created a branch that is updated to the most recent 3.0

https://github.com/Haneke/HanekeSwift/issues/348

But, nothing is ever that simple.  Just copying-&-pasting the update into the terminal doesn't seem to work.  

[computername:ProjectFolderName chriscantley$ pod update"HanekeSwift", :git => 'https://github.com/Haneke/HanekeSwift.git', :branch => 'feature/swift-3'
-bash: https://github.com/Haneke/HanekeSwift.git,: No such file or directory 

And now off to StackExchange to figure out what is going on. There I found a suggestion to update Cocoa Pods.

sudo gem update cocoapods

nope...
So I downloaded the Branch and performed a compare using BeyondCompare and everything was different in the primary directory.  So I just moved everything over from the 3.0 branch to my copy.

After the migration...

After the migration...

Other errors came up, however on removing the derived data (remove or rename the folder for your project at /Users/chriscantley/Library/Developer/Xcode/DerivedData), cleaning the project, executing it to build, cleaning again and then building... a Whole new set of errors came up.

But this one is resolved.

 

Error : does not contain bitcode!

Wade Cantley

Ok, so here is the full error.


ld: ‘/Users/chriscantley/Documents/GITXCodeRepository/ MyMobi/Pods/Google/Libraries/libGGLAnalytics.a(GGLContext+Analytics.o)’ does not contain bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target. for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)

But why?

Turns out that not all of the frameworks I am using are Bitcode savvy. 

But what is this Bitcode thing?

Having Bitcode on compiles an app out to a format that allows apple to thin out the application and make it more efficient.  This is on by default as far as I can tell in XCode 7.  However if you are using frameworks that don't use bitcode, this conflict will come up.  So evidently it needs to be all or nothing when it comes to bitcode.  

In this case I am using Google analytics and it is NOT using bitcode.  So the solution turns out to be pretty simple.

  1. Find bitcode under your build settings
    1. Click on your project
    2. Select you app target.
    3. select "Build Settings"
    4. Search for "bitcode" which should present the setting under "Build Options"
    5. Set "Enable Bitcode" to "No"

1. Click on your project

1. Click on your project

2. Select your app target

2. Select your app target

3) select "Build Settings"

3) select "Build Settings"


4) Search for "Bitcode"

4) Search for "Bitcode"

5) Set "Enable Bitcode" to "no"

5) Set "Enable Bitcode" to "no"


Archive and the error should go away.