I am creating an app that displays different colours as text strings on labels based on input from steppers. As part of this, I am trying to write a function in swift to set the string value for the labels, so that the code can be used multiple times for multiple labels and steppers. The function uses an inout parameter and a variable parameter:
func function(var Extra: Int, inout LabelName: String) {
if Extra == 0 {
LabelName = "Black"
}
if Extra == 1 {
LabelName = "Brown"
}
if Extra == 2 {
LabelName = "Red"
}
if Extra == 3 {
LabelName = "Orange"
}
if Extra == 4 {
LabelName = "Yellow"
}
if Extra == 5 {
LabelName = "Green"
}
if Extra == 6 {
LabelName = "Blue"
}
if Extra == 7 {
LabelName = "Violet"
}
if Extra == 8 {
LabelName = "Grey"
}
if Extra == 9 {
LabelName = "White"
}
if Extra == -1 {
LabelName = "Gold"
}
if Extra == -2 {
LabelName = "Silver"
}
}
When I try to call the function using
function(ValueLabel1Extra, ValueLabel1String)
I get a Swift Compiler Error saying 'Expected Declaration', which, from prior knowledge and some research, is an error where a function isn't declared properly if at all.
I'm not entirely sure what is not declared, but by trial and error it seems that the function itself is what isn't declared, but only when I call it. The problem persists even after several re-writes and edits to the code.
Thanks in advance!
&beforeValueLabel1Stringon function call. Except that, it works like a charm for me on a playground.