# Chapter 4. why can not use slider (var) in sliderMoved?

**URL:** <https://forums.kodeco.com/t/chapter-4-why-can-not-use-slider-var-in-slidermoved/36362>\
**Category:** iOS Apprentice\
**Created:** [November 8, 2017, 3:38am UTC](https://forums.kodeco.com/t/chapter-4-why-can-not-use-slider-var-in-slidermoved/36362 "2017-11-08T03:38:46Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ceoit](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@ceoit](https://forums.kodeco.com/u/ceoit)\
**Post date:** [November 8, 2017, 3:38am UTC](https://forums.kodeco.com/t/chapter-4-why-can-not-use-slider-var-in-slidermoved/36362/1 "2017-11-08T03:38:46Z")

</div>

why i can not use slider(var) in sliderMoved, instead of (\_slider : UISlider)  
but can use in startNewRound???

 ![52 AM](https://raywenderlich-com-v3-forums.s3.amazonaws.com/original/3X/9/2/9271228adeb3348d77755a1a457c841fb7861a76.png)

---

<div class="post-metadata">

**Author:** ![shogunkaramazov](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/shogunkaramazov/32/108826_2.png) [@shogunkaramazov](https://forums.kodeco.com/u/shogunkaramazov)\
**Post date:** [November 8, 2017, 3:58am UTC](https://forums.kodeco.com/t/chapter-4-why-can-not-use-slider-var-in-slidermoved/36362/2 "2017-11-08T03:58:08Z")

</div>

@ceolt It should actually work after all - what is the error you are getting at runtime?

---

<div class="post-metadata">

**Author:** ![ceoit](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@ceoit](https://forums.kodeco.com/u/ceoit)\
**Post date:** [November 8, 2017, 4:07am UTC](https://forums.kodeco.com/t/chapter-4-why-can-not-use-slider-var-in-slidermoved/36362/3 "2017-11-08T04:07:31Z")

</div>

yes, when i build my code above, then slide the slider…

---

<div class="post-metadata">

**Author:** ![fahim](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/fahim/32/110943_2.png) [@fahim](https://forums.kodeco.com/u/fahim)\
**Post date:** [November 8, 2017, 5:40am UTC](https://forums.kodeco.com/t/chapter-4-why-can-not-use-slider-var-in-slidermoved/36362/4 "2017-11-08T05:40:33Z")

</div>

It sounds as if you might not have connected your IBOutlet to the slider. Can you check if that is the case? If not, can you copy and paste the full error (especially the top) part that you see in the Xcode console?

---

<div class="post-metadata">

**Author:** ![ceoit](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@ceoit](https://forums.kodeco.com/u/ceoit)\
**Post date:** [November 8, 2017, 5:50am UTC](https://forums.kodeco.com/t/chapter-4-why-can-not-use-slider-var-in-slidermoved/36362/5 "2017-11-08T05:50:52Z")

</div>

i connected IBOutlet to slider.  
My question is "Why i must write (\_slider : UISlider) in sliderMoved??  
And Why i can’t use IBOulet… slider for sliderMoved, instead of assign new variable (\_slider) "???  
Why??  
@IBAction func sliderMoved() {  
currentValue = lroundf(slider.value)  
print(“The value of the slider is now : (currentValue)”)  
} // ERROR // use IBOutlet slider for sliderMoved()…

Here is my console :

 ![06 PM](https://raywenderlich-com-v3-forums.s3.amazonaws.com/original/3X/3/d/3d6033a6f81213b453d717d6d51edf120bce15a1.png)

---

<div class="post-metadata">

**Author:** ![fahim](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/fahim/32/110943_2.png) [@fahim](https://forums.kodeco.com/u/fahim)\
**Post date:** [November 8, 2017, 6:12am UTC](https://forums.kodeco.com/t/chapter-4-why-can-not-use-slider-var-in-slidermoved/36362/6 "2017-11-08T06:12:35Z")

</div>

Your error/crash is because you changed the signature of the `sliderMoved` method. I think you originally had the method as `@IBAction func sliderMoved(_ slider:UISlider) ` and then later changed it to `@IBAction func sliderMoved() `.

Those are treated as two different methods by the compiler since one has a parameter and the other does not. Since you connected the outlet to the original method, you would need to disconnect it and then re-connect it for the right method to be hooked up.

Does that part make sense?

As far as your question as to why you must write the method as `@IBAction func sliderMoved(_ slider:UISlider) `, that depends on what you are trying to do. You should be able to write the method without the parameter, but as I said, you need to hook up your method again in that case if you originally had the method with the parameter.

Hope this helps 🙂

---

<div class="post-metadata">

**Author:** ![ceoit](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@ceoit](https://forums.kodeco.com/u/ceoit)\
**Post date:** [November 8, 2017, 6:20am UTC](https://forums.kodeco.com/t/chapter-4-why-can-not-use-slider-var-in-slidermoved/36362/7 "2017-11-08T06:20:20Z")

</div>

> [@fahim](#):
>
> Those are treated as two different methods by the compiler since one has a parameter and the other does not. Since you connected the outlet to the original method, you would need to disconnect it and then re-connect it for the right method to be hooked up.
> 
> Does that part make sense?
> 
> As far as your question as to why you must write the method as @IBAction func sliderMoved(\_ slider:UISlider), that depends on what you are trying to do. You can certainly write the method without the parameter, but as I said, you need to hook up your method again in that case if you originally had the method with the parameter.
> 
> Hope this helps 🙂

Show me how i can write `@IBAction func sliderMoved().` instead of `@IBAction func sliderMoved(_ slider:UISlider)`, but compile is fine, and build success…  
Why i must write `@IBAction func sliderMoved(_ slider:UISlider)`, instead of `@IBAction func sliderMoved().`.  
if i just write `@IBAction func sliderMoved()`, and use slider: IBOutlet, like starOver() used.  
Why can not use IBOutlet slider in sliderMoved(), but starOver() can???

---

<div class="post-metadata">

**Author:** ![fahim](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/fahim/32/110943_2.png) [@fahim](https://forums.kodeco.com/u/fahim)\
**Post date:** [November 8, 2017, 6:41am UTC](https://forums.kodeco.com/t/chapter-4-why-can-not-use-slider-var-in-slidermoved/36362/8 "2017-11-08T06:41:11Z")

</div>

I have already answered your question. You _can_ write the method as `@IBAction func sliderMoved() ` as I mentioned above. It will compile fine. I just tried it and it works fine here.

If you cannot get it to compile with the method name that way, please provide a screenshot of the compiler error at that point showing the code you’re using.

---

<div class="post-metadata">

**Author:** ![system](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@system](https://forums.kodeco.com/u/system)\
**Post date:** [April 23, 2018, 7:39pm UTC](https://forums.kodeco.com/t/chapter-4-why-can-not-use-slider-var-in-slidermoved/36362/9 "2018-04-23T19:39:00Z")

</div>

Closed on April 23, 2018, 7:39pm UTC

This topic was automatically closed after 166 days. New replies are no longer allowed.
