|
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. |
TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and more!
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.