I have a method which retrieves data from an API request:
let session = URLSession.shared
let url = URL(string: "http://eventregistry.org/json/article?conceptUri=http%3A%2F%2Fen.wikipedia.org%2Fwiki%2FAfghanistan&lang=eng&action=getArticles&articlesSortBy=date&resultType=articles")!
let task = session.dataTask(with: url) { (data, _, _) -> Void in
if let data = data {
print(JSON(data: data))
completion()
}
}
task.resume()
The link works perfectly when accessing through a browser, however when debugging line by line in XCode, none of the code within the let task = session.dataTask is executed and so the print is not printed within the log.
I am running through emulator and my laptop has internet, im just not sure why this is not working.
Does anyone understand why?
data.count(since I don't know what your "JSON" class/struct is), and changed "http" to "https" (as per Xcode's warning), and ran it. It shows 15594 bytes returned. I even put a breakpoint in the completion handler, and it was triggered. Can you be more specific about exactly how you're running this in the debugger?