I'm getting the error:
Invalid parameter not satisfying: [constraint isKindOfClass:[NSLayoutConstraint class]]
for my auto-layout constraints code written in Swift:
let d:NSDictionary = ["scrollView": scrollView]
let hc:NSArray = [NSLayoutConstraint.constraintsWithVisualFormat("H:|[scrollView]|", options: NSLayoutFormatOptions.allZeros, metrics: nil, views: d)]
let vc:NSArray = [NSLayoutConstraint.constraintsWithVisualFormat("V:|[scrollView]|", options: NSLayoutFormatOptions.allZeros, metrics: nil, views: d)]
view.addConstraints(hc)
view.addConstraints(vc)
Does anyone have an idea what this error tries to tell me? As far as I know the parameter is of type NSArray
with NSLayoutConstraint
objects in it. I suspected I have to explicitly define the arrays as NSArray
but that's not solving it.
NSLayoutConstraint.constraintsWithVisualFormat
already returns an NSArray
so you don't need to wrap it in another array. So try:
let d:NSDictionary = ["scrollView": scrollView]
let hc:NSArray = NSLayoutConstraint.constraintsWithVisualFormat("H:|[scrollView]|", options: NSLayoutFormatOptions.allZeros, metrics: nil, views: d)
let vc:NSArray = NSLayoutConstraint.constraintsWithVisualFormat("V:|[scrollView]|", options: NSLayoutFormatOptions.allZeros, metrics: nil, views: d)
view.addConstraints(hc)
view.addConstraints(vc)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With