You can learn about NSStackView by looking at the documentation here: https://developer.apple.com/documentation/appkit/nsstackview?language=objc
Some examples of NSStackView are as follows:
var row1 = NSStackView.alloc().initWithFrame(NSMakeRect(0,0,mainViewWidth,25))
row1.setViews_inGravity([view1,vewi2, view3, etc...],NSStackViewGravityLeading)
However sometimes I don’t want to use frames and I just use the
stackViewsWithViews init function
var stackView = NSStackView.stackViewWithViews([view1, view2, view3, etc...])
You’ll want to reference that documentation above to learn what all the properties are for each of the functions (such as NSLayoutAttributeFirstBaseline, etc)
You also might find an overview of what the type of organizational views you have access to and when to use them to be helpful. WWDC 2017 has a nice video of this: https://developer.apple.com/videos/play/wwdc2017/218/
One other thing, I would recommend trying to build your UI with Interface Builder and Xcode first. It’s a nice way to learn about all the properties the UI components have. For example, when you search for “button” in the library you get to see a bunch of ways buttons are used (checkboxes, popup buttons, etc). Moreover, when you drag it onto your ViewController you can get a properties panel full of all the wonderful options to tweak the button. It’s really a great way to learn how to build native UI.
For example, one of the lines of code in the article is:
dropdown = NSPopUpButton.alloc().initWithFrame(NSMakeRect(0, viewHeight - 230, (viewWidth / 2), 22));
This is cocoascript. You can also write it in objective-c like this:
dropdown = [[NSPopUpButton alloc] initWithFrame:NSMakeRect(0, viewHeight - 230, (viewWidth / 2, 22)];
You can learn a bit more about cocoascript here: https://developer.sketchapp.com/guides/cocoascript/
The tldr version is that
- All colons are converted to underscores (the latest underscore is optional).
- Each component of the selector is concatenated into a single string with no separation.
As such, a selector such as
executeOperation:withObject:error: is converted to the function name
Lastly, your issue with the window crashing. It’s a little hard to tell exactly without seeing more code (or all of it) but looking at the article they didn’t properly include a reference to the dropdown. You should probably store it as a variable or a constant.
const dropdown = NSPopUpButton.alloc().initWithFrame(NSMakeRect(0, viewHeight - 230, (viewWidth / 2), 22));
[dropdown addItemWithTitle:"Optie 1”];
/* Note you can also write this with cocoascript as */
const in front of