Before adding CalcView as a subquery, try pasting this line of code:
calcView.translatesAutoresizingMaskIntoConstraints = false
This should solve your problem.
By default in UIView / NSView this property is set to YES / true and creates its own set of restrictions based on the autoresist mask. These automatic restrictions conflict with those you created in the code.
This clearly indicates this in the error description. Lines 2 and 3 show that there are 2 sets of vertical limits for one view - NSView:0x600000120f00 , which seems to be your calcView.
<NSLayoutConstraint:0x618000082440 V:|-(0)-[NSView:0x600000120f00] <NSAutoresizingMaskLayoutConstraint:0x618000084100 h=--& v=&-- V:|-(-2)-[NSView:0x600000120f00]
They are both vertical. First you need to click the top view from above without borders. The second (created automatically) wants to bind it with a small margin, presumably taken from the way it is laid out in Interface Builder.
UPDATE
Create a new Cocoa application project and paste the following code:
override func viewDidLoad() { super.viewDidLoad() let view = NSView() view.translatesAutoresizingMaskIntoConstraints = false self.view.addSubview(view) //Making it red just to see a little better. Ignore this two lines. view.wantsLayer = true view.layer?.backgroundColor = CGColorCreateGenericRGB(1, 0, 0, 1) //----------------------------------------------------------------- let views = ["view" : view] self.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("|-[view]-|", options: NSLayoutFormatOptions(0), metrics: nil, views: views)) self.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-[view]-|", options: nil, metrics: nil, views: views)) }
The newly created NSView is attached to the main view of View Controllers with standard fields (8 points, which are indicated as "-" in the line of the visual format) and resizes from the main view (see the figures). A little tip - you do not need to specify "H:" in visual format, only "V:". Horizontal by default.
This should give you an idea of how programmatic actions are adding constraints. The code may not be optimal, I have code in Obj-C and I know very little Swift.
I uploaded your project. The error is probably somewhere in your complex hierarchy of xib views and manipulations. But this is a completely different story. Also be careful with scroll views, they are a bit complicated when it comes to self-timer, you can find many possibilities for this on SO. Happy coding :)

