[quote='741498022, Frameworks Engineer, /thread/722924?answerId=741498022#741498022']
When selection changes in the sidebar, the navigation system pops value-based links off the stack.
[/quote]
I think I'm seeing this in my macOS Swift app but in my case it's not the behavior I want. I have navigation links in the sidebar and various views in the detail view. But I want to preserve the state of each detail view so that when the user navigates back to a particular view the navigation path and scroll state is preserved. But the system seems to be resetting the state of each detail view even if I control the navigation paths myself. Is there a way to disable this behavior?
Post
Replies
Boosts
Views
Activity
Thanks for the suggestion. When I make this change the detail view no longer changes to reflect the selection in the sidebar. Do I need to make changes to the detail view for this to work?
In case anybody else is struggling with this, the solution I finally found that works is like this. Basically not to use a selectable list as suggested above, and use willSet and didSet on the selected item to update the path.
Observable
class NavigationModel {
private var navigationPaths = [RootSection: NavigationPath]()
var path = NavigationPath()
var selectedSection: RootSection? = RootSection.home {
willSet {
if let selectedSection {
navigationPaths[selectedSection] = path
}
}
didSet {
if let selectedSection, let newPath = navigationPaths[selectedSection] {
path = newPath
}
}
}
init(sections: [RootSection]) {
for section in sections {
navigationPaths[section] = NavigationPath()
}
}
func selectSection(_ section: RootSection?) {
if let section, selectedSection == section {
navigationPaths[section] = NavigationPath()
} else {
selectedSection = section
}
}
}
From what I've read elsewhere it's best for performance to avoid conditionals inside ForEach loops like this. Pre-filtering the data is preferable.
I'm still having this problem with XCode 15 / iOS 17. The solutions posted above didn't work for me.
What finally did work was turning off wifi on the device.
I'm seeing something similar here. If I use ArtworkImage the image loads fine but if I try to load it via URLSession I get a bunch of errors like this:
[ICUserIdentityStore] Failed to load properties for identity <ICUserIdentity 0x301b99b00: [Active Account: <unresolved>]>. err=Error Domain=ICError Code=-7013 "Client is not entitled to access account store" UserInfo={NSDebugDescription=Client is not entitled to access account store}
I'd like to hear what the recommended approach is here too. I've discovered that the id for an album is not a reliable handle for an Album because it can be different on two different devices even if referencing the same Album in the library. But a user's library might contain content they've added themselves so UPC also doesn't seem like a real solution.