How to link two min max sliders with swiftui iOS15

0 votes

I have two sliders to filter the results. One of the sliders sets minimum value another sets maximum value. Filters work properly, except min value can be increased to a value more than max and max can be lowered below min.

How can I link these sliders so that min does not exceed max and max does not go below min?

Here is the code:

@State private var minimum: Double = 98.0
@State private var maximum: Double = 1000000.0

var filteredProducts: [Product]

var body: some View {
    List {
        Section(header: Text("Filters")){
            DisclosureGroup("Price range") {
                Slider(value: $minimum, in: 98...1000000) {
                    Text("\(minimum)")
                } minimumValueLabel: {
                    Text("min")
                } maximumValueLabel: {
                    Text("\(minimum, specifier: "%.0f")")
                }
                
                Slider(value: $maximum, in: 98...1000000) {
                    Text("\(maximum)")
                } minimumValueLabel: {
                    Text("max")
                } maximumValueLabel: {
                    Text("\(maximum, specifier: "%.0f")")
                }
            }
        }
    }
}

var slideresults: [Product] {
    if minimum == 0 && maximum == 1000000000.0 {
        return filteredProducts
    } else {
        return filteredProducts.filter {
            $0.price > minimum &&
            $0.price < maximum
        }
    }
}


 

Sep 22 in Others by gaurav
• 18,960 points
12 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Others

+1 vote
0 answers

How to split a number with coma betweeen two colunms

Jul 3, 2019 in Others by anonymous
184 views
0 votes
1 answer

How to communicate gRPC example working with Node.js?

hi.. you can read below link, it ...READ MORE

answered Dec 2, 2019 in Others by Narendra Reddy Dalli
1,552 views
0 votes
1 answer
0 votes
1 answer

How to deal with a Project Manager with controlling nature?

It depends on whether the Project Manager ...READ MORE

answered Jul 29, 2020 in Others by Sirajul
• 59,190 points
190 views
0 votes
1 answer

How to give space between two Textfield in Flutter?

Hi@akhtar, There is various way to give space ...READ MORE

answered Sep 8, 2020 in Others by MD
• 95,360 points
1,759 views
0 votes
1 answer

How to run two commands in one line in Windows CMD?

Hi@MD, You can use the Logical And operator ...READ MORE

answered Oct 5, 2020 in Others by akhtar
• 38,230 points
3,804 views
0 votes
2 answers

In List of Dicts, find min() value of a common Dict field

lst = [{'price': 99, 'barcode': '2342355'}, {'price': ...READ MORE

answered Aug 31, 2018 in Python by Omkar
• 69,190 points
5,916 views
0 votes
0 answers

Use of min and max functions in C++

Are std::min and std::max better than fmin ...READ MORE

Jun 2 in C++ by Nicholas
• 6,240 points
50 views
0 votes
1 answer

Use of min and max functions in C++

The functions fmin and fmax are designed ...READ MORE

answered Jun 21 in C++ by Damon
• 4,960 points
378 views
0 votes
0 answers

How can I get the maximum or minimum value in a vector?

In C++, how can I find the greatest or minimum value in a vector? Is it correct to assume that it would be similar with an array? Do I require an iterator?  I tried max element, but I kept receiving errors. vector<int>::const_iterator it; it = max_element(cloud.begin(), cloud.end()); error: request for ...READ MORE

Jun 27 in C++ by Nicholas
• 6,240 points
30 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP