0
I’m finishing a small project to learn Swift but there is a small problem in joining more variables in the output.
@IBOutlet weak var Nome: UITextField!
@IBAction func CalcularIMC(_ sender: AnyObject) {
imc = ((p * 200) / (a * a)) * 100 / 2
var str = "";
if imc < 16
{
str = NSString(format: "O seu IMC é %.2f, Peso Abaixo", imc) as String
lblresultado.backgroundColor = UIColor.orange
}
lblresultado.text = str;
There’s definitely some parentheses missing, but it was just for show. My problem is here :
(format: "O seu IMC é %.2f, Peso Abaixo", imc)
In this text I also want to show the variable Nome
which is at the beginning of the code I showed you.
Gave me error while displaying text. <uitextfield: 0x79e964e0; frame.... text = " The name I wrote" clipstobound... a thing like this s:
– ChrisAdler
It seems to me that name is not a string.
– Reginaldo Rigo
Name is text. It will be the user name for example : Maria
– ChrisAdler
Try it this way: str = Nsstring(format: "%@ your BMI is %.2f, Weight Down", "Maria", imc) as String
– Reginaldo Rigo
This is how it works:
– ChrisAdler
So. This means that no text is coming to the function. The function needs to receive a string and name is not a string. It seems to me that it is an object. You must pass something, like: Name.Text. I don’t have SWIFT here to validate it, but go that way.
– Reginaldo Rigo
To receive Var Name I created a text box . @Iboutlet Weak var Name: Uitextfield!
– ChrisAdler