I was following a CodePath tutorial on creating a Tip Calculator. The author is using an earlier version of Xcode while I am using Xcode 8.2. The problem I faced is that while the author was able to drag and associate an object’s action with an existing method (at around the 31 minute mark), I was unable to do so and it was only prompting me to create a new action. I scoured the web for answers and most seemed to suggest ensuring that the `ViewController` class was correctly named in the StoryBoard. Some suggested clearing the cache and restarting the OS but none of those solutions worked.

I finally checked whether Xcode stopped supporting this feature in 8.2 but the Xcode docs suggested that this is supported. Then I realized that all the examples had the function parameter type as `AnyObject` whereas mine had `Any`. I changed it to `AnyObject` and, voilà, I was able to associate the action with the existing method. It looks like the Create Action prompt defaults to a type of `Any` in Xcode 8.2 and I don’t see an option of `AnyObject` although it can be typed in. So, there you have it. If this helped you, I’d love to hear it in the comments.


Categories: Tech