Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error Nil default argument value of cannot be converted to type 'NSLayoutFormatOptions'

Tags:

xcode7

swift2

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

like image 436
uplearned.com Avatar asked Sep 20 '15 12:09

uplearned.com


1 Answers

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])
like image 129
Eric Aya Avatar answered Oct 19 '22 04:10

Eric Aya