Using return values

How do I use the returned value of a function? Specifically I'm trying to use the returned value of a slider object and put that value in a text field. Sounds simple but not for me. 😁 I've only been using Swift for about a week now. So I'm very new to it. Can I put the returned value in a variable? Then I can use it. Can I also convert a string to an integer and vise versa? Wow, I have a lot to learn! Any help would be appreciated.

A "slider object" is not a function. It's a slider object. It has a property named "value" that you can query at any time, or you can add an action to it so that the slider will call a method you define whenever its value changes (UIControlEventValueChanged).


Once you have the value as a floating point number, you need to convert that to a string if you want to set that to a text field or label. You should search for "NSNumberFormatter" for some examples of how to format numbers as strings in the user's preferred locale. (And also convert strings to numbers.)


Anyway, this is not a question about Xcode, so I suggest you move it to a more appropriate forum - perhaps Getting Started. That way you can also tell people what platform you're talking about (tvOS, watchOS, iOS, OS X).


I would also suggest you spend some time (a week is not enough) going through Apple's getting started documentation and other introductory material such as raywenderlich.com tutorials, the Stanford CS193P course, etc. That should get you started in understanding how UI elements interact with your code.

Thanks for the reply. You're definitely right, I need to learn the basics first. I'll check out those references you mentioned. Also, how do I move this post to the Getting Started forum?

Moving to another forum should be an option in the 'Actions' menu(s) up on the right.

Using return values
 
 
Q