Swift 2.0 Constraintswithvisualformat

Swift 2.0 constraintsWithVisualFormat

You should change your viewBindigsDict to

var viewBindingsDict = [String: AnyObject]()
viewBindingsDict["webView"] = webView

as suggested in the comments, and also in the format options, you cannot use 0, instead:

view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[webView]|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: viewBindingsDict))

or more simplier as @MartinR suggested:

view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[webView]|", options: [], metrics: nil, views: viewBindingsDict))

Using Autolayout Visual Format with Swift?

this works for me with no error:

let bar:[AnyObject]! = NSLayoutConstraint.constraintsWithVisualFormat(
nil, options: NSLayoutFormatOptions(0), metrics: nil, views: nil)

update

the line above may not be compiled since the 1st and 4th parameters cannot be optionals anymore.

syntactically those have to be set, like e.g. this:

let bar:[AnyObject] = NSLayoutConstraint.constraintsWithVisualFormat("", options: NSLayoutFormatOptions(0), metrics: nil, views: ["": self.view])

update

(for Xcode 7, Swift 2.0)

the valid syntax now requests the parameters's name as well, like:

NSLayoutFormatOptions(rawValue: 0)

NOTE: this line of code shows the correct syntax only, the parameters itself won't guarantee the constraint will be correct or even valid!

Swift 2.0 calendar components error

As of Swift 2, NS_OPTIONS (such as NSCalendarOptions) are mapped to Swift as a OptionSetType
which offers a set-like interface. In particular, "no options"
can now be specified as [] instead of nil:

let components = cal.components(unit, fromDate: calcDesp!, toDate: calHoy!,
options: [])

See also Swift 2.0 - Binary Operator "|" cannot be applied to two UIUserNotificationType operands
and the recently added answers to How to create NS_OPTIONS-style bitmask enumerations in Swift? for more information.

Swift 2.0 animating images

I hope I will help you

@IBOutlet var myImageView: UIImageView!
@IBOutlet var animationBtn: UIButton!

var imageList = [UIImage]()

imageList.append(UIImage(named: imageName))
or
imageList += [UIImage(named: imageName)]

VFL constraints in swift: Crashes due to no superview

Those constraints are made between the label and its superview. The constraints should be added to that superview, not to the label.



Related Topics



Leave a reply



Submit