|
Hello I have an array of families that I add via a sheet. I would like to gradually add members to each family that would appear in the family list. I have. created struct family and people then class which contains array families. I can add a family via the navigation link, but I can't add a family member to the given family
|
|
This should work. You need to uncomment your
|
|
How to declare it?
|
|
In you ObervableObject add this variable
then you can get family by:
to get people array in family
or in preview you can create them directly. This is for preview so you need to pass some sample data. |
|
this is my struct an class file
and adont know what to do
|
|
Ok, then better remove static var and place that directly into your preview
|
|
now I have no errors. unfortunately, they still do not place members in individual families |
|
|
|
|
|
|
|
In your ContentView you create an object |
|
|
|
Can you upload that to github and share the link. Looking at those files you posted I am already confused what are you planning to do. As i understood you want to create a family then add people in there? I posted sample before, can you just copy paste that code in your Xcode, run it and say if this is the behavior you would like to have. This is what I posted in your previous thread. https://www.hackingwithswift.com/forums/swiftui/how-to-create-items-in-items/20488/20534. Just add your data model as well to make it compile. |
|
Now i copy your code from yesterday but ij dont have how prite PreviewProvider. https://github.com/rabrez/test my project |
|
To make the code compile from github you just need to update few lines for in previews:
and that's it. |
|
|
|
As I already completed another approach post it as well. So you can choose. This one maybe more easier to follow that the one with lots of binding I used before.
|
|
|
|
|
|
|
|
I have some isue. How to add other items under people
|
|
|
|
As you already have Family conform to Equatable you can use
well if no typos from my side, this should work |
|
|
|
Have you tried to run on simulator? I suspect, the item might be added but it does not appear after addition. The issue is the same, you change the underlying value of @Published property, and as there is no change in property itself it does not publish the change. Or the item is not added at all? |
|
it seems that the item will not be added. I think I've tried all the combinations, but it's not enough with my knowledge |
|
|
|
|
|
I'd like to, but with current state of the project I have no idea what are you trying to do there. I tried to clone your project but on Preview it says Active Scheme does not build this file. No idea what is wrong with preview even. |
|
So exactly... the project will be for an apiary In the first preview (family) I will create apiaries (I have more) In the second view (people) I will create hives in the given apiary in the third preview, I want to make a report (notes) for each beehive. |
|
As there are too many changes you want to implement, I have revised the logic. You will want to adjust to your data which you'd like to collect. But this one is more or less workable. Though it is still not good idea to save everything to UserDefaults. It's recommended to keep it less than 100kb. Otherwise it will affect app startup. |
|
|
|
There is no right answer to your question. All depends on the scope of your project and what you are plannig to do later. But as a starting point you can save it in a file in your documents directory. Look at the second part of this lesson, where Paul explains how to do that. Minimal changes to your current project will be required. https://www.hackingwithswift.com/books/ios-swiftui/introducing-mvvm-into-your-swiftui-project |
|
|
|
Here's an updated version of your code with the necessary modifications: swift Copy code import SwiftUI struct NovyClovek: View { @ObservedObject var people: Families @Environment(.dismiss) var dismiss var family: Family
} struct NovyClovek_Previews: PreviewProvider { static var previews: some View { NovyClovek(people: Families(), family: Family()) } } Make sure that the Family and People structs and the Families class are defined correctly. Additionally, ensure that you pass the appropriate Family object when navigating to the NovyClovek view. With these modifications, you should be able to add a new person to the selected family. |
|
SAVE 50% All our books and bundles are half price for Black Friday, 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.
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.