mercredi 22 avril 2015

Can't pass nil to two optional parameters

I'm in the process of converting an Objective-C category to a Swift extension to provide simplified methods for adding constraints. One method for equally spacing views has the following signature,

func addAndEquallySpaceViews(views: [UIView], leftOrTopSpace: CGFloat?, rightOrBottomSpace: CGFloat?, options: NSLayoutFormatOptions?)

I call it like this,

self.view.addAndEquallySpaceViews([view1, view2], leftOrTopSpace: nil, rightOrBottomSpace: nil, options: .AlignAllBottom)

I want to be able to pass nil to the leftOrTopSpace and rightOrBottomSpace parameters, but when I pass nil for both of them, I get a series of compile time errors. I can pass nil for either of them alone, but not for both. Why can't I pass nil for both optional parameters?

The errors I'm getting seem to be non-specific, and not related to the line in question,

enter image description here

Aucun commentaire:

Enregistrer un commentaire