IOS - Swift Nsstring

Asked

Viewed 61 times

0

Good,

I’m making an app where I’ll measure users' BMI. I created the layout but in the code I’m having problems.

I have a button that when sliding changes the value of height or weight.

var w:Float = 75

alturachg(_ sender:UISlider) {
h = sender.value
lblAltura.text = NSString(Format: " %2.f m", h) }

Before closing } forces me to have the String to make no mistake.

  • 2

    Do you want to convert from Nsstring to String type? If that’s it just do the following: NSString(Format: " %2.f m", h) as String

  • 1

    lblAltura.text = String(format: "%.2f m", sender.value)

1 answer

1

The estate value of UISlider returns a float.

Just make a cast for String. You can do something like this:

h = String(sender.value)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.