advanced patterns of NSStackView on macOS 13.6 when dynamically adding/removing views
I've been banging my head against this for hours. I’m working with an scenario with `NSStackView` on macOS 13.6 where adding and removing arranged subviews dynamically causes the layout to behave unpredictably. Specifically, when I remove a view from the stack view and then add a new view immediately afterward, the stack view does not refresh its layout correctly. Sometimes it overlaps other views or even fails to show the new view altogether. Here’s a simplified version of what I’m doing: ```swift let stackView = NSStackView() let viewToAdd = NSView() let viewToRemove = stackView.arrangedSubviews.first if let viewToRemove = viewToRemove { stackView.removeArrangedSubview(viewToRemove) viewToRemove.removeFromSuperview() } stackView.addArrangedSubview(viewToAdd) stackView.needsLayout = true stackView.layoutSubtreeIfNeeded() ``` I’ve tried manually calling `layoutSubtreeIfNeeded()` and setting `needsLayout` to `true`, but it doesn’t seem to have any effect. I also looked into using an animation block when modifying the stack view, but that didn’t help either. Interestingly, if I add a short delay before adding the new view, it behaves as expected, but I don’t want to rely on that as a solution since it feels hacky. I also noticed that if I put the `removeArrangedSubview()` and `addArrangedSubview()` calls within a `viewWillAppear()` or `viewDidLoad()`, the scenario doesn't occur. How can I ensure the stack view updates correctly without needing to introduce arbitrary delays? Am I missing something obvious?