Modify the GameScene Class to Handle Paid Continues

Similar to how you added the numberOfFreeContinues property in Save and Load the Number of Continues, you need to add a property to track the number of paid continues; one that uses a custom getter and setter.

Open the GameScene.swift file, and below the code that adds the numberOfFreeContinues property, add the following code:

 var​ numberOfPaidContinues: ​Int​ {
 get​ {
 var​ qty: ​Int​ = 0
 for​ product ​in​ ​GameData​.shared.products {
 if​ product.id.​contains​(​"continue"​) {
  qty += product.quantity
  }
  }
 return​ qty
  }
 set​(newValue) {
 let​ product = ​GameData​.shared.products.​filter​(
  {$0.id.​contains​(​"continue"​)}).first
  product?.quantity = newValue ...

Get Apple Game Frameworks and Technologies now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.