0

I'm trying to make a little close simplification, and I seem to have missed something basic. I want the following snippet:

        let updateStackView = NSStackView(views: [updateField])
        updateStackView.orientation = .horizontal
        updateStackView.distribution = .fill
        updateStackView.alignment = .centerX

to look more like this:


let updateStackView = stack(views[updateField], orient: .horizontal, dist: .fill, align: .centerX)

    func stack(views:[NSView],
               orient: NSUserInterfaceLayoutOrientation,
               dist: NSStackView.Distribution,
               align: NSLayoutConstraint.Attribute) -> NSStackView {
        let s = NSStackView(views: views)
        s.orientation = orient
        s.distribution = dist
        s.alignment = align
        return s
    }

But, the returned StackView does not get the attributes assigned. What am I missing?

The original snippet works as expected. The factored code doesn't.

wblj
  • 21
  • 3
  • I tried your code (fixed the missing `:`) and it works for me. Post a [mre] please. – Willeke Dec 28 '22 at 13:41
  • 1
    argh. I figured out why it wasn't working. Thanks for the impetus to create a small example; I should've done that before. It looks like using the incorrect .alignment overrides the orientation. So, I had a .horizontal orientation specified with a .centerX alignment. Same thing happens with .vertical and .centerY. Probably in the docs somewhere, but I guess I missed it. – wblj Dec 28 '22 at 21:32

0 Answers0