0

This is a follow up question to How to have 10 characters total and make sure at least one character from 4 different sets is used randomly

this is my code so far

let sets = ["ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz", "1234567890", "\"-/:;()$&@.,?!'[]{}#%^\\|~<>€£¥•.,"].map { Array($0.characters) }

var randoms = sets.map { $0.random }

while randoms.count < 10 {
  randoms.append(sets.random.random)
}

var convertedElems = String()

let something = randoms.shuffled()

for key in something {
  convertedElems = String(key)
}

uniqueRoomID.text = randoms.shuffled()

Im getting an error saying cannot convert [Element] to type "String"

So i tried a for loop but that only converts 1 at a time when its supposed to do all 10

my other question is i tried storing a character in a variable and then setting a text field.text equal to that variable and nothing happened

What am i doing wrong here

Community
  • 1
  • 1
RubberDucky4444
  • 2,330
  • 5
  • 38
  • 70

1 Answers1

1

Your randoms.shuffled() is an array of Characters. You need to convert it back into a String.

Change this:

uniqueRoomID.text = randoms.shuffled()

to this:

uniqueRoomID.text = String(randoms.shuffled())
vacawama
  • 150,663
  • 30
  • 266
  • 294