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

Project 3

Forums > 100 Days of SwiftUI

I have a question about the part of Project 3 where you have to change WeSplit so that the total amout is red if the user picks a 0% tip. I couldn't figure out how to call a function on the Picker selection or anywhere else in the body property, I kept getting an error that my function did not conform to the View protocol. I ended up using a computed property to complete the challenge and it worked perfectly, but I'm still wondering is it possible to call a function within a Picker view, and if so how. Thank you.

2      

No you can not call a function within a Picker(selection: label: content:) because the selection require a Binding variable the label require Text() and the content: requires a View of content to display.

Check Apple Document - Picker.

To you try not to include methods/functions inside the body of the View, It a good idea to have the logic somewhere else, so in your case it was the good ways to do it.

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.