Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

valueForUndefinedKey "currentUnityController": Crash #51

Open
guptatarun84 opened this issue Sep 1, 2017 · 7 comments
Open

valueForUndefinedKey "currentUnityController": Crash #51

guptatarun84 opened this issue Sep 1, 2017 · 7 comments

Comments

@guptatarun84
Copy link

After below line its crashing:
UnityAppController* currentUnityController = (UnityAppController *)[delegate valueForKey:@"currentUnityController"];

***Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ valueForUndefinedKey:]: this class is not key value coding-compliant for the key currentUnityController.

Any help please?

@eric-krikey
Copy link

I have used this tutorial before with no issues, but I just tried it in a new project and I'm getting the exact same issue.

@guptatarun84
Copy link
Author

guptatarun84 commented Sep 5, 2017

I could able to resolve the issue by integrating unity to my existing codebase as I am able to locate the currentUnityController object created in app's bridging header file under derived sources.

I somehow feel this have something to do with a new project or the bridging headers are not connected well. Still confused!

@eric-krikey
Copy link

eric-krikey commented Sep 5, 2017

I was able to fix it by going to the 'Build Settings' for the target and setting 'Swift Language Version' from 4.0 to 3.2. It seems to be an issue with Swift classes in general not being key value coding-compliant, whereas Objective-C classes almost always are because most are a subclass of NSObject.

****However, this is not a long-term solution. I hope that Apple updates Xcode 9 to support this or introduces a feasible fix. Or Unity could too, I guess.

@guptatarun84
Copy link
Author

Indeed! it worked... Thanks for your help. Appreciated!

@igoredington
Copy link

igoredington commented Sep 6, 2017

Hi, If you want to continue to use Swift 4.0, only you need to do is:

@objc var currentUnityController: UnityAppController?

In Swift 4.0, when you need to access the swift code in the ObjectC code you have to put "@objc" before the attribute.

You can see this in: https://developer.apple.com/library/content/documentation/Swift/Conceptual/BuildingCocoaApps/InteractingWithObjective-CAPIs.html

@guptatarun84
Copy link
Author

I tried that earlier, but can't able to make that work. However I will still give that a try! Thanks

@eric-krikey
Copy link

This worked great. Thank you @igoredington!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants