古いバージョンのSwiftサンプルコードを持ってきて動かそうとしたときに、エラーとなったのとその対応方法
"options: nil"の記述がダメっぽい。
Nil is not compatible with expected argument type 'NSLayoutFormatOptions'
preferredView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|[imageView]|",
options: nil, metrics: nil, views: ["imageView": imageView]))
preferredView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|[imageView]|",
options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: ["imageView": imageView]))
- error Nil default argument value of cannot be converted to type ‘NSLayoutFormatOptions’
![](https://cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-icon.png?v=c78bd457575a)
error Nil default argument value of cannot be converted to type 'NSLayoutFormatOptions'
I have upgraded to swift 2 and this function has created a headache for me. This is causing the error when trying to run...
func addConstraints(format format: String, options: NSLayoutFormatOptions? = nil, metrics: [String: AnyObject]? = nil, views: [String: UIView])
func addConstraints(format format: String, options: NSLayoutFormatOptions, metrics: [String: AnyObject]? = nil, views: [String: UIView])
コメント