NavigationSplitView doing weird things

I've got an array of items that I use as a source of truth, and I copy that array into another array (filteredItems) and use that to power a NavigationSplitView (on MacOS).

I can sort the items in filteredItems by create date, title, last modified date, forward and reverse, no problem. And I have a text filter field that I can use to filter out items in the filteredItems field and that works great.

So far so good.

But if I reduce the filter text or remove it altogether—thus increasing the number of items in filteredItems or returning it to its original state—weird things happen.

Clicking on items in the navigation portion of the view doesn't bring up the detail view as it did before the reduction and re-adding of items.

After clicking on several of the non-responsive nav items, it freezes up.

I know there are different ways to do this, but my view is set up like this:

NigationSplitView { // filter tool, etc. List { ForEach(ascending ? filteredItems : filteredItems.reversed()) { item in NavigationLink { ItemView(item: item) } label: { // yadda yadda } } }

(ascending is just a boolean state variable)

I know there's not much detail here, but I should be able to change filteredItems as much as I want, right? Or is this construct wrong?

Do you get the same results with just the relevant code in a small test project? If so, please share a link to your test project. That'll help us better understand what's going on. If you're not familiar with preparing a test project, take a look at Creating a test project.

Let me know about posting the project, but I think I've narrowed it down to the specific snippet that causes the problem.

If, let's say I add an item to items and want it to show up in the view, I can just do:

filteredItems = items

...and everything works great.

But part of the functionality is that the field for entering a new item title to create it searches existing items and shows only matches, and I've simplified that search down to:

        var tempItems = items
        if newText == "" {
//            NSLog("No filtertext. Items: \(items.count)")
        } else {
            tempItems = tempItems.filter {
                $0.title.lowercased().contains(newText.lowercased())
            }
        }         
        filteredItems = tempItems

...and if that runs and reduces the size of the list, it's fine. But if it runs again and the size increases again, then everything goes crazy.

So imagine you have three items, The King, The Queen, and The Jack. If you search on "the", it doesn't reduce the list at all, so if you were to either add a new item just called "the", it'd be fine, and it would also be fine if you deleted that filter.

However, if you typed the letter "i", the list would be reduced to "The King", and if you deleted that "i" filter, the full list would return, but the returned items would be non-responsive.

Heeeelllllp?

OK, I've decided this is a bug in the framework, for two reasons.

  1. It worked until Sequoia.
  2. I modified the project to make it work on the iPad as well as the Mac, and it works perfectly fine on the iPad.
NavigationSplitView doing weird things
 
 
Q