-1

On my application developed in swift, I would like to be able to execute a script once, it is a request GeoFire and I would like that it makes its request once then stops. I tried conditions and loops

if ([name of the varialble] <= 1)
{
// Execute the query,
}
else if ([name of the variable > 1)
{
// Otherwise stop the query
}

But that never works. Thank you for your help

François
  • 67
  • 6

1 Answers1

-1

You can use dispatch_once in your viewDidLoad:

static dispatch_once_t once;
dispatch_once(&once, ^
{
    // Code to run once
});

This will make the code run only once until you exit and close your app.

Usman Javed
  • 2,437
  • 1
  • 17
  • 26