lundi 20 janvier 2020

Can't get random value with an empty range

I have 2 random numbers and one of them connected to other. Below is my code:

func funcrandomNumber()
  {
    number = String(Int.random(in: 1..<100))
    randomLabel.text = number
  }

func funcrandomSubMathNumber()
  {
    if let number = randomLabel.text , !number.isEmpty
    {
       math2Number = String(Int.random(in: 1..<Int(number)!))
    }
    else
    {
       funcrandomNumber()
    }
  }

sometimes it works perfectly but sometimes it gets the error:

Fatal error: Can't get random value with an empty range

How to check if number is not empty?




Aucun commentaire:

Enregistrer un commentaire