Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Yellow Warning Triangle When Trying to .append to NavigationPath

I am trying to navigate to another view after my function returns a CloudKit record (which is triggered by a user tapping a button), however upon testing, and successful retrieval of said record, the screen displays a yellow warning triangle ⚠️, and does not navigate to the ProfileView.

This is a simplified version of my code:

@State var invites: [CKRecord] = []
@State private var path = NavigationPath()

var body: some View {
    NavigationStack (path: $path) {
        List {
            
            ForEach(invites, id: \.recordID) { invite in
                
                if let acceptedBy = invite["acceptedInvite"] as? CKRecord.Reference {
                    Button(action: {
                        
                        fetchUserAccount(userToFetch: acceptedBy) { accountRecord in
                            DispatchQueue.main.async {
                                
                                if accountRecord != nil {
                                    path.append(accountRecord) // Works, but causes ⚠️ to show on screen
                                }
                            }
                            
                        }
                    }, label: {
                        Text("\(invite.recordID.recordName)")
                    })
                }
            }
            
        }
    }.navigationDestination(for: CKRecord.self) { record in
        ProfileView(profileRecord: record)
    }
}

As mentioned, I’m trying to present ProfileView(profileRecord: record), however instead, no error is shown in the logs, however the main view is removed and a yellow warning triangle ⚠️ gets displayed instead.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

move your .navigationDestination(...) inside the NavigationStack, just after List.

you also need to ensure that accountRecord is of type CKRecord not Optional CKRecord, that is
try path.append(accountRecord!)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading