mardi 27 juillet 2021

Edit Swift Function and If Else To Increase Count

I paid to have an app built last year and now I need to make some changes to the code.

I let users create one free VIBE and now I want them to be able to create 3 free VIBES. I believe all I need to change is the

''' if count < 1 '''

Changed Too:

''' if count < 3 '''

But I think I may need to also change

''' userDefault.set(1, forKey: "count") '''

To 3 instead of 1.

But ultimately I do not know.

Here is the full function.

    func trackVibesCount() -> Bool {
      let userDefault = UserDefaults.standard
      if let count = userDefault.value(forKey: "count") as? Int {
          if count < 1 {
              let newCount = count + 1
              userDefault.set(newCount, forKey: "count")
                return false
          } else {
            return true
          }
      } else {
          userDefault.set(1, forKey: "count")
            return false
      }
     }

Appreciate all the help, thanks.

Aucun commentaire:

Enregistrer un commentaire