|
So I took a large break in between day 77 and everything else so I expect I am missing something easy. When I append to the people Array in my content view model it crashs. I'm, assuming there is a better way to handle this but honestly I've spent hours on this going in circles and just can't work out what I've messed up (Because of this some of the code is quite a mess). I know in other laungages appending to collections whilst they are being enumerated on in the view can cause issues but I'm not sure of the swiftui way to handle this. Any help would be greatly appreciated. Code is available here for convenience: https://github.com/PaulLocksley/100Days-of-SwiftUI-Day77-Help-Link Content View
Content view model
Add person view:
|
|
My guess without testing is the below Change your AddPerson code as below:
|
|
Thanks for the help @Bnerd, Unfortunatly that doesn't work as AddPerson doesn't know what ViewModel is wihtout the context of ContentView. Is there any particular reason you think this is the path to go down? |
|
My mistake I don't know why but I thought your model was an extension of View ...I know silly.. I just noticed that in your model the people array is private(set), private set means you can read but not write, does it work if you remove the(set) ?
|
|
Lookign back over it the viewmodel in addperson was a relic of a different attempt to fix this so I removed it. Setting private(set) should be fine because its being set insite the view model via a function call inside of ContentView. I have removed it for now but it did not change the behaviour, when I press "Add Person" in the add person sheet the program crashes with Thread 1: EXC_BAD_ACCESS (code=2, address=0x16f57bff8) |
|
|
|
Ok found it... Change 01 that makes the most mess :P Line 27 of your ContentView
Change 02, remove the Challenge3App.swift I tried , now it works. |
|
|
|
actually the padding() is obvious, read your code carefully, you have
I was surprised that even compiled.. |
SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.
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.