|
Hell I'm playing with Please see my code, at the last line of my code making the array All the properties has a default value of What is the problem here ? (I am making the array in order to use the it as an
Thank you in advance Boat |
|
The problem is this: Properties of classes and structs in Swift have to be completely initialized before you can use the class or struct. You initialize properties by either a) supplying a default value, or b) assigning a value in an So let's look at what we have here. I'm not sure what exactly you are trying to do here or I would suggest another way of approaching it. |
|
Thank you I'm trying to 1, create an Array with $binding , where users can input each item in the array. (It is their own hand-picking choices from 1-8, thus integer) 2, in the second view promoted by sheet(), I want to show by So the second view screen is not for inputing any data but rather showing what they have chosen in the first screen. That's why I'm playing with @StateObject and @ObservedObject Boat |
TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts! Sponsor Hacking with Swift and reach the world's largest Swift community! |
|
I'm still not entirely clear what you're doing. Some But here's a simple example of what I think you're trying to do:
There's no need to store the user's choices as both individual |
|
thank you so much. I tried your code as a second screen and it works. But I see you declared a class What I wanted was to pass in the value from main screen where the user chose all their options from 1 to 8. Shouldn't I : 1, Delcare the Class in the main page. 2, make a ? Thank you in advance, Boat |
|
Well, that example was meant to demonstrate the screen where the user selects their choices. If you want a separate sheet to display those choices, you can do something like this:
But yes, you are correct that you would declare and initialize your |
|
But when I tried to "divide bigger chunk into smaller chunks" , meaning, I maded a "Second View file" and copied the Just Like Paul demonstrated : https://www.hackingwithswift.com/books/ios-swiftui/sharing-an-observed-object-with-a-new-view To make it compile, I will need to modify the I modifed the last line of the Preview code into But Xcode warns me: Cannot convert value of type 'PickerArrayViewModel.Type' to expected argument type 'PickerArrayViewModel'
|
|
In the preview, you need to create an instance of
|
|
The reason my code in the preview didn't work was I missed a pair of I haven't learned Thank you Boat |
|
In order for In this particular case, we're looping through a |
|
I need to go back and study on how the twice There's still lots to learn and reflect from this thread. Really appreciate your effort and help, Have a great week Patrick ! Boat |
BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.
Sponsor Hacking with Swift and reach the world's largest Swift community!
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.
Link copied to your pasteboard.