iosswiftsprite-kitheyzap

Play interstitial ad every 3rd game in Swift


I've found an acceptable answer for Objective-C here:

Play interstitial ad every 3rd game

But, I'm trying to do the same thing in Swift. I'm looking how to write the Static variable.

Here's the Objective-C code:

static int count = 0;

-(void) GameOver {
   if(count != 0 && count % 3 == 0)
     [HZInterstitialAd show];

   count++;
}

Solution

  • private var count = 0
    
    func GameOver {
      if (count != 0 && count % 3 == 0) {
        HZInterstitialAd.show()
      }
      count++
    }