UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

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?

2      

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).

2      

@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.

2      

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.

2      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

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

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

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.