My main issue revolves around dispatch_once
. I am converting this objective-c code in Swift :
dispatch_once(&_startupPred, ^{
[MPPush executeUnsafeStartupWithConfig:[MPConfig configWithAppKey:appKey withAppId:appID withAccountId:accountId forProduction:inProduction] authToken:authToken];
});
Swiftify doesn't help much. So I dig a bit deeper. Apparently dispatch_once is no longer in Swift. As per this accepted answer, I can achieve this by :
let executeStartup = {
self.executeUnsafeStartupWithConfig(config: MPConfig.config.configWithAppKey(appKey: appKey, withAppId: appId, withAccountId: accountId, forProduction: inProduction), authToken: authToken)
}()
_ = executeStartup
But by doing so, I get this warning :
Constant 'executeStartup' inferred to have type '()', which may be unexpected
So first, is this the correct way of replacing dispatch_once
in Swift ? Secondly how do I handle this warning ?