Unrecognized selector UIDeviceRGBColor countByEnumeratingWithState:objects:count:
Asked Answered
S

2

14

I know this is kind of a dupe, but I don't have enough reputation yet to comment on the original post and, while I don't have an answer, I do have more useful information (a concrete example). Moderators, feel free to move this to the proper location.

When compiling my code using the latest XCode 8 beta 6 (iOS 10 SDK), I get an exception "Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIDeviceRGBColor countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0x600000071340'"

This happens during the call:

    auto viewController = [[[UIViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];

I have isolated the problem by whittling down my project to the bare minimum that will compile and still exhibit the problem. You can download it here:

Example project

Note that I took out lots of code, nearly all classes are gone, which results in a lot of warnings (not errors) for nonexistent classes referenced from the xib. But that doesn't matter, the code still compiles and runs just fine with the iOS 9 SDK. After compiling with the iOS 10 sdk, however, it crashes both in the simulator and on devices running iOS 9.

You can work around the problem by changing "#if 0" into "#if 1" in the file "HackForUnrecognizedSelectorInIOS10.m". This adds a category defining the missing selectors for UIColor. But obviously you can't add that to shipping code, it's just a temporary stopgap measure to continue developing.

I filed a bug report (28153870). But if anyone has any more information on how to avoid this problem without ugly hacks, any information is welcome.

Thanks

Michel Colman

Spireme answered 4/9, 2016 at 14:52 Comment(0)
K
41

When I try to compile and run my project with the same configuration (XCode 8 beta 6, iOS 10 SDK), I encountered a similar issue, except that my error message was:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIDeviceRGBColor length]: unrecognized selector sent to instance 0x600000479280'

And I noticed that this issue only occurs when the view is init by using interface files, i.e. Xib and Nib. I solved this issue by:

  1. Open your interface file, in the right panel, navigate to the File Inspector tab.

  2. Change the attribute highlighted to "iOS 7.0 and Later" (or whatever iOS version later) enter image description here

Then compile and run your project again, this should fix your issue, though I am not sure about the reason behind this. I tried the same with your sample project and it solves the issue too.

Kurrajong answered 6/9, 2016 at 6:38 Comment(4)
That does indeed solve it! Apparently the deployment target needs to be at least 6.0. I had it set to "Deployment Target (5.1)". Also, when I manually edited the xib in a text editor to set <deployment version="1296" identifier="iOS"/> (1536 is hex 510, i.e. iOS 5.1), the error came back. When I set it back to 1536 (hex 600, i.e. iOS 6.0), it worked OK again.Spireme
O, by the way, I got the [UIDeviceRGBColor length] as well on some occasions. That's why I included both selectors in the ugly hack file in the project. Meanwhile I found out that this hack doesn't really work right: even though the crashes disappear, so does certain functionality. Some buttons stopped working, for example. Although sometimes they did work. There seems to be some nondeterminism going on there.Spireme
This did not work for me. I tried setting the "Later" version but I still get the error. I also looked into the file and I don't see the version that @MichelColman showed. I just see this, <deployment identifier="iOS"/>Tyndale
What does this setting do? Why does it fix the issue and what was causing the problem?Lanna
A
4

In my case, I needed to change the project deployment target to 8.0 in the product general settings. Thanks to the hint from the accepted answer!

Assuage answered 5/11, 2016 at 10:25 Comment(2)
This worked for me. But it still seems like a workaround.. is there a explanation anywhere of the cause and/or a fix needed?Dipteral
In my case, I had to specify it in the Podfile. That's my fault because Pod logs a warning if the platform is not specified.Gordan

© 2022 - 2024 — McMap. All rights reserved.