I have strange problem with AutoLayout in Swift 2.0
self.webView = WKWebView()
self.view.addSubview(self.webView!)
var viewBindingsDict: NSMutableDictionary = NSMutableDictionary()
viewBindingsDict.setValue(self.webView, forKey: "webView")
self.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[webView]|", options: 0, metrics: nil, views: viewBindingsDict))
self.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|[webView]|", options: 0, metrics: nil, views: viewBindingsDict))
And I'm receiving error:
'String' is not convertible to 'StringLiteralConvertible'
for "H:|[webView]|" and "V:|[webView]|"
I do not know if im missing something
Update:
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))
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