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.
With Xcode 7.1.1 Not fixed but this workaround helped me:
if let protocolStr = JSON["version"] as AnyObject as! String {
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.
All I had to do was type the key string (“version”) to NSString
like so:
if let protocolStr = JSON["version" as NSString] as? String {
…
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With