Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 7 - Strange cast error that refers to XCUIElement

I've updated my code to XCode 7 and Swift 2.0, now some of my tests fail and I see a list of 40 warnings in the Test build that are completely unrelated with the code they refer to. The warning message is:

"Cast From 'XCUIElement' to unrelated type 'String' always fails" 

And this is an example of a row that produces the warning:

if let protocolStr = JSON["version"] as? String{

I'm not using XC user interface tests yet... so I cannot understand why this code is referring to that class. Any idea?

Update: November 9 With XCode 7.1 the issue is still there.

like image 417
MatterGoal Avatar asked Sep 22 '15 11:09

MatterGoal


3 Answers

With Xcode 7.1.1 Not fixed but this workaround helped me:

if let protocolStr = JSON["version"] as AnyObject as! String {
like image 182
Eis Avatar answered Sep 22 '22 13:09

Eis


I think you already fixed your issue, but in case anyone else is looking at this:

The problem is that JSON is of type AnyObject I'm guessing, at it doesn't know that you can index it as a dictionary. If you cast it as [String : AnyObject] before hand it won't give you an error. (like you noticed)

edit: As for why it's giving you that error specifically, I'm not sure. Probably a bug.

like image 22
ssrobbi Avatar answered Sep 23 '22 13:09

ssrobbi


All I had to do was type the key string (“version”) to NSString like so:

if let protocolStr = JSON["version" as NSString] as? String {
    …
}
like image 23
SushiGrass Jacob Avatar answered Sep 24 '22 13:09

SushiGrass Jacob