mardi 10 septembre 2019

I'm trying to select a random string to populate individual labels whilst removing the selected one each time

I am trying to reuse a piece of code which works perfectly for multiline strings in one of my published apps but I can't figure out why it's different and doesn't work for this project.

It doesn't seem to be because of the different labels or the time delayed action but I could be wrong.

    var randomNumberSelection = ["1", "2", "3", "4", "5"]

    let index = Int(arc4random_uniform(UInt32(randomNumberSelection.count)))
    let removed = randomNumberSelection.remove(at: index)
    guard !removed.isEmpty else
    {
        return
    }
    if label1.text == nil && label2.text == nil && label3.text == nil && label4.text == nil
    {
    DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(1), execute:
    {
    self.label1.text = removed

    if self.label1.text != nil && self.label2.text == nil && self.label3.text == nil && self.label4.text == nil
    {
    DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(2), execute:
    {
    self.label2.text = removed
    }
    })
    }
    })

If I just use the array it works well but occasionally duplicates and I want to eliminate the possibility of duplicates.




Aucun commentaire:

Enregistrer un commentaire