Orkhan Alizade
Orkhan Alizade

Reputation: 7559

How to set constraint programmatically in Swift2?

I want to set constraint programmatically, but my Swift 1.2 code doesn't works! What had changed in Swift 2?

let topConstraint = NSLayoutConstraint(item: nvc, attribute: .Bottom, relatedBy: .Equal, toItem: nvc.superview, attribute: .Bottom, multiplier: 1, constant: 0)
nvc.superview!.addConstraint(topConstraint)

but it returns me

Type of expression is ambiguous without more context

How to fix it?

Upvotes: 0

Views: 172

Answers (1)

Knight0fDragon
Knight0fDragon

Reputation: 16837

The only thing I can see being ambiguous is nvc, since you do not show us how it is defined. I typed your code using self.view in place of nvc and self.view.superview in place of nvc.superview, and the code compiled fine.

Upvotes: 2

Related Questions