8
votes

After swift 3 conversion I have been getting this error.

'NSInvalidArgumentException', reason: '-[_SwiftValue nsli_superitem]: unrecognized selector sent to instance 0x600000a54820'

The code in question is this, it use to work fine with swift 2:

let views = ["newView": userLabel]
let widthConstraints = NSLayoutConstraint.constraints(withVisualFormat: "H:[newView(0)]", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: views)
userMainLabel.addConstraints(widthConstraints)
1

1 Answers

19
votes

This is a issue with swift 3, where the dictionary is treated as a [String: UIView?]

The fix is to assign the type as not optional

let views: [String: UIView] = ["newView": userLabel]