Xcode 7 Sent from XCUIElement to an unrelated type "String" always fails when retrieving JSON

I am trying to get values ​​from a JSON array and I get the error message "Cast from 'XCUIElement!" for an unrelated string always fails. "

I am using Xcode 7 with iOS 9.1.

My code is as follows:

let url = NSURL(string: urlAsString)! let urlSession = NSURLSession.sharedSession() let jsonQuery = urlSession.dataTaskWithURL(url, completionHandler: { data, response, error -> Void in if (error != nil) { print(error!.localizedDescription) } do { let jsonResult = (try NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.MutableContainers)) as! NSMutableArray // print (jsonResult) for usernames in jsonResult { let influencer_username = usernames["influencer_username"] as! String print("influencer_username: \(influencer_username)") } 
+6
source share
2 answers

With Xcode 7.1.1 Not fixed, but this workaround helped me:

let influencer_username = usernames["influencer_username"] as AnyObject as! String

+6
source

I was able to solve this problem by removing "themostplayedTests" from my target membership.

-1
source

All Articles