Check out example codes for "run a function only once swift". It will help you in understanding the concepts better.
Code Example 1
// Declare your "once-only" closure like this
private lazy var myFunction: Void = {
// Do something once
}()
...
// Then to execute it, just call
_ = myFunction
Learn ReactJs, React Native from akashmittal.com