BLACK FRIDAY SALE: Save 50% on all my Swift books and bundles! >>

SOLVED: WeSplit - Day 17 Issue

Forums > 100 Days of SwiftUI

Hey everyone, I'm running through the wesplit part of 100 days of SwiftUI and I ran into an issue! When creating the picker, it isn't behaving like it is in Paul's tutorial. What did I do wrong here?

import SwiftUI

struct ContentView: View {
    @State private var checkAmount = 0.0
    @State private var numberOfPeople = 2
    @State private var tipPercentage = 20

    let tipPercentages = [10, 15, 20, 25, 0]

    var body: some View {
        //NavigationView {
            Form {
                Section {
                    TextField("Amount", value: $checkAmount, format:
                        .currency(code: Locale.current.currencyCode ?? "USD"))
                        .keyboardType(.decimalPad)

                    Picker("Number of people", selection: $numberOfPeople) {
                        ForEach(2..<100) {
                            Text("\($0) people")
                        }
                    }
                }
                Section {
                    Text(checkAmount, format: .currency(code:
                        Locale.current.currencyCode ?? "USD" ))
                }
            }
        //}
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

My apps behavior: The "Number of people isn't greyed out like in pauls, the chevron pointing right in Pauls isn't on mine. There's two, one pointing up and the other down. When I go to surround it in the navigationView (commented out in the copy/paste above) nothing changes. Does anyone have any suggestions by chance?

   

Nothing wrong with your code, as far as it goes.

Paul's solution also does the same (up / down chevron) in Xcode14 / iOS16. Apple have I think (though I have not checked and confimred yet) changed the way these lists are shown in the view.

The preview now matches the simulation ('Number of people' is not greyed out in either the preview or the simulation).

   

@greenAmber has the right answer.

What you're seeing is an evolution in how the Picker interface element is implemented

@twoStraws noted that the element will change its display properties based on which device you're running it on.

See -> Adaptive Views

In the video (min 4:30) and also in the text he notes:

SwiftUI’s pickers serve multiple purposes, and exactly how they look
depends on which device you’re using and the context where the picker is used.

In previous versions of iOS, you had to add a NavigationView so the Picker could segue to another screen where you'd pick the number of people. But in iOS 16, the interface has been updated. Now, instead of the segue to another screen iOS add a popover allowing you to select on the same screen as the Picker element.

   

OK for the interest of science and my own annoyance at the same thing.

I created a new simulator device (it required just north of 5gb of my storage) which is an iPhone 13 Pro running iOS 15.0

When running Day 17 WeSplit code, just as others have already pointed out, the preview code runs JUST like what is in the video.

   

Save 50% in my Black Friday sale.

SAVE 50% To celebrate Black Friday, all our books and bundles are half price, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.