Get variable from inside of a method : <p>I am quite new to swift and I am learning to make HTTP requests from an API.</p>

<p>Right now I have this struct</p>

<pre><code>struct CNJokesProvider  {
    let url = URL(string: "https://api.chucknorris.io/jokes/random")!

    func getRandomJoke() -&gt; String {
        var request = URLRequest(url: url)

        request.httpMethod = "GET"

        let session = URLSession.shared

        let task = session.dataTask(with: request, completionHandler: { data, response, error -&gt; Void in
            do {
                let json = try JSONDecoder().decode(CNJokesResponse.self, from: data!)
            } catch {
                print("\(error)")
            }
        })

        task.resume()

        //return json.value
    }
}
</code></pre>

<p>and you can see the declaration of the json constant.
I need to get the data from the constant to return it from this getRandomJoke function.
I tried to make it a struct property but I couldn't make it work.</p>
