I am trying to fetch the values from JSON array and i am getting an error "Cast from 'XCUIElement!' to unrelated String always fails."
I am using Xcode 7 with iOS 9.1.
My code is as below:
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)")
}
With Xcode 7.1.1 Not fixed but this workaround helped me:
let influencer_username = usernames["influencer_username"] as AnyObject 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