Yellow Warning Triangle When Trying to .append to NavigationPath

Advertisements

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.

>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!)

Leave a ReplyCancel reply