LAST CHANCE: Save 50% on all my Swift books and bundles! >>

Day 16: Picker not producing same result as shown in video

Forums > 100 Days of SwiftUI

Howdy,

The below code is part of Day 16's example, however it does not produce the same result as shown in the accompanying video for said day which can be seen at: https://youtu.be/wBIv4QRawY0?t=141starting or on the HWS site (https://www.hackingwithswift.com/books/ios-swiftui/creating-views-in-a-loop) then manually jumping to the time stamp of 2:21

struct ContentView: View {
    let students = ["Harry", "Hermione", "Ron"]
    @State private var selectedStudent = 0

    var body: some View {
        VStack {
            Picker("Select your student", selection: $selectedStudent) {
                ForEach(0 ..< students.count) {
                    Text(self.students[$0])
                }
            }
            Text("You chose: Student # \(students[selectedStudent])")
        }
    }
}

Has the functionality of Picker changed? In all the videos & examples I could find plus dinking around I could not get the label "Select your student" to appear in any other way than inside a Form { } & this is not the same result as in the video.

Show up every day!

3      

I stumbled across the same thing. It appears Apple has changed the way pickers handle labels. But I have found very little actual documentation.

Perhaps Apple assumes developers will prever to manually create visual labels for pickers. But the picker label is still important for things like things like voiceover.

Since this is the very first actual project in 100 days of swiftui I hope Paul updates this because it can be very frustrating for students starting out.

4      

Still no explanation to this ???

3      

Yes the label do not show in the Picker unless you are in Form instead of a VStack this changed in one of the early betas of iOS 13/4, however you still need the label string as this is use with VoiceOver.

Think it was because the formatting of String did not fit very well therefore is not needed as most of the time .labelHidden(true)

If you want a label in a VStack the put Text("Select your student") before the Picker

3      

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