TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

Updating NSManagedObject property appears to close View

Forums > SwiftUI

Hi, I'm running through the HWS+ Ultimate Portfolio App and have hit a bug thats driving me crazy. The issue is when i edit a Project, lets say the title, as soon as i enter a character in the textfield my edit view is closed and i'm put back to the list view. For reference I'm actually at lesson 18, and so everything prior to that is in place.

This code is almost identical to that being used in EditItemView which is working fine. As far as local storage and iCloud is concerned, the update, even a 1 char change is recorded fine.

The reason for the title of this post is because when i was doing some debug i commented out the 3 lines in the ProjectEditView.Update func which updates the nsmanagedobject Project properties with the local state vars. When the properties are not updated, the problem does not occurr, my editprojectview remains active and i can carry out multiple edits in the textfields. Obvious not saved but you get the point. I can trace through and see the onChange binding extension is hit, passing in the update handler as expected. I can also see the OnDisapear modifer is hit in projectedittview.

Has anyone seen anything like this before? Thanks in advance.

3      

I assume that the NavigationLink is the one on the Section header, as I had a similar problem.

In my case the Edit screen would sometimes work perfectly OK for an extended time, and I was able to enter all the data and text input with no problems. Then, for no apparent reason, it would start working in the way that you described, where entering a single character would dismiss the edit view.

As a temporary measure, since in my case Section contains a List view, I put the NavigationLink on the list items, and that works robustly with no problems.

I have not ascertained as to why the editing using the NavigationLink in the Section header is often flaky, and if anyone knows why, it would be appreciated.

In the meantime, although not elegant, at least there is a workaround using a Navigation Link on the List view.

4      

Hi @Greenamberred

That appears to be the issue. I've moved the NavigationLink out of the Section header and it appears to be working as expected. Very strange behaviour. Will play around a bit more but many thanks for pointing me in that direction.

3      

Hacking with Swift is sponsored by RevenueCat.

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.

Learn more here

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.