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

VisionOS : update attachments for model entities when CoreData Entity is updated.

Forums > SwiftUI

How do I update Attachments to a VisionOS Entity when a referenced CoreData Entity is updated?

I am getting close!

So far, I can get UI updates automatically in a SwiftUI View when a CoreData Entity is updated. For example, the following list will update automatically when "name" is updated on a StudyParticipantEntity after the view was created, as expected:

          @FetchRequest(fetchRequest: StudyParticipantEntity.fetch(), animation: .bouncy) var studyParticipants:FetchedResults<StudyParticipantEntity>

  List(studyParticipants, id: \.self){ studyParticipant in
        ZStack{
            Text(studyParticipant.name!)

            }
        }

However, I DO NOT get automatic updates to UI in attachments to the model entity that reference the same core data entity:

Creating the attachment, passing in the same core data entity studyParticipantEntity:

      let attachmentRightLegView = AttachmentFollowedRightLeg(
              name: followedRunTimeComponent.attachmentTag,
              studyParticipantEntity: theStudyParticipantEntity
               )
               .tag(attachmentTagRightLeg)

Important: I DO get automatic updates in the attachment if I instead reference a typical value type in the viewModel.

Any suggestions? Thanks much!

2      

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!

Reply to this topic…

You need to create an account or log in to reply.

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.