在swift中只执行一次脚本

问题描述 投票:-1回答:1

在我在swift中开发的应用程序中,我希望能够执行一次脚本,它是一个请求GeoFire,我希望它一旦停止就发出请求。我试过条件和循环

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

但这永远不会奏效。谢谢您的帮助

swift xcode if-statement geofire
1个回答
-1
投票

你可以在你的dispatch_once中使用viewDidLoad:

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

这将使代码只运行一次,直到您退出并关闭应用程序。

© www.soinside.com 2019 - 2024. All rights reserved.