|
Swift, storyboards I can acces to information in a JSON in a url. It works well. My question is: can I have the func outside any class? In the example I provide, If I put func getData outside the class ViewController, is there a way I can call let result2 when I click the button check?
|
|
|
|
I do not know how to do it. I tried many things. For instance:
|
|
The usual way to return a value from an asynchronous action (such as using
And you would call it like this:
Even better would be to supply a
|
|
It gives me an error: Escaping closure captures non-escaping parameter 'completion' I do not understand what does it mean. |
|
Change:
to:
An escaping closure is one which isn't called immediately but may outlive the life of the function in which it is called. Since |
|
All this is very complicated for a beginner like me. There are several things I do not fully understand. That is two levels ahead to what I know. Anyway, it works well. |
SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until February 9th.
Sponsor Hacking with Swift and reach the world's largest Swift community!
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.