I have upgraded to swift 2 and this function has created a headache for me.
This is causing the error when trying to run the app. I have no idea how to fix this as I'm trying to upgrade it to swift 2. I have done an extensive search but not able to remedy the code. The error occurs on : NSLayoutFormatOptions = nil
when creating the function.
internal extension UIView {
func addConstraints(format format: String, options: NSLayoutFormatOptions = nil, metrics: [String: AnyObject]? = nil, views: [String: UIView]) {
addConstraints(NSLayoutConstraint.constraintsWithVisualFormat(format, options: options, metrics: metrics, views: views))
}
func addUniversalConstraints(format format: String, options: NSLayoutFormatOptions = nil, metrics: [String: AnyObject]? = nil, views: [String: UIView]) {
addConstraints(format: "H:\(format)", options: options, metrics: metrics, views: views)
addConstraints(format: "V:\(format)", options: options, metrics: metrics, views: views)
}
}
Thank you if you can help. :)
Yours Sincerely Gerard Grundy
Your options
parameter is not declared as Optional, so you can't set a default value of nil
.
Either make options
an Optional:
func addConstraints(format format: String, options: NSLayoutFormatOptions? = nil, metrics: [String: AnyObject]? = nil, views: [String: UIView])
or remove = nil
from the signature:
func addConstraints(format format: String, options: NSLayoutFormatOptions, metrics: [String: AnyObject]? = nil, views: [String: UIView])
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