Learn Courses My Dashboard

Slider s and retaining the value for use in another view

Hi everyone, I am a complete newbie to SwiftUI

I am trying to create an app that uses several sliders, all the same but needs to be used in various variables throughout various views

I have created the basic slider, that works fine, it is when I try and adapt it to use the output in different views, I am unable to achieve this, any help would be most welcome

Hi @PS3Pupil!

I’m glad you’re exploring SwiftUI! Can you give me more context about your app? if you can show some code or screenshot for Xcode editor and UI that would be great!

Hi Josh, to be honest any code that I did have as been destroyed by trying to find a solution to this.

I am trying to build an app for 10 Pin Bowling, the basic data that I am trying to create with the sliders is to establish where the bowler stands when making certain shots, the shots are where they would stand when making a strike shot (when trying to knock down all pins on the first attempt). the 7 pin shot ( where they would stand when trying to knock just the 7 pin down( and the 10 pin shot same as the 7 pin but obviously with the 10 pin

The aim of this part of the app is to show which board they should stand on (boards are numbered 1 thru 39) based on a set of rules created by a coach that I know

import SwiftUI

class pinT: ObservableObject {

@Published var pin:Double = 20


struct test2: View {

var pinr:Double = 20

@EnvironmentObject var settings: pinT

var body: some View {

VStack {

Slider(value: settings.$pin)




The errors that I am getting are

Cannot convert value of type ‘Published.Publisher’ to expected argument type ‘Binding’

Generic parameter ‘V’ could not be inferred

I have removed some issues, but then others appear, any help greatly appreciated


Slider(value: settings.$pin)


Slider(value: $settings.pin)

That probably won’t solve all of your issues in your app, but it takes care of this immediate problem presented here.

Also, two suggestions to make your code easier to understand when you post asking for help in the future:

  1. Name your types starting with a capital letter (e.g., PinT instead of pinT). That’s the Swift convention.
  2. Give your variables and types more descriptive names than things like PinT and pinr. That both makes it easier to understand when reading and makes autocomplete more useful when writing.
1 Like