If you want to keep it packed in some type you better use enum
instead:
enum RandomMessage: String, CaseIterable {
case message1 = "Message1"
case message2 = "Message2"
case message3 = "Message3"
case message4 = "Message4"
case message5 = "Message5"
static var get: String {
return allCases.randomElement()!.rawValue
}
}
This way you will guarantee that it will only have “fields” with messages, and if you get new messages you can just add new case and it will automatically be in allCases
array.
To get random message do this:
let message = RandomMessage.get // one of the messages
3
solved How to get random value from struct