[英]swift cannot convert value of type (_, _) -> _ to expected argument type '((_, CGFloat)) -> _
I am using a library URLEmbeddedView 我正在使用库URLEmbeddedView
It defines following code in its library: 它在其库中定义以下代码:
func addConstraints(with view: UIView, center: CGPoint, multiplier: CGFloat = 1) {
view.translatesAutoresizingMaskIntoConstraints = false
addConstraints([
(.centerX, center.x),
(.centerY, center.y)
]
.flatMap {
.init(item: view,
attribute: $0,
relatedBy: .equal,
toItem: self,
attribute: $0,
multiplier: multiplier,
constant: $1)
})
}
We are generating preview of link through the Library but following error is occurring : 我们正在通过库生成链接的预览,但是发生以下错误:
cannot convert value of type (_, _) -> _ to expected argument type '((_, CGFloat)) -> _" at .flapMap line. 无法在.flapMap行将(_,_)-> _类型的值转换为期望的参数类型'((_,CGFloat))-> _“。
I am familiar with Objective-C
but not with Swift
. 我熟悉Objective-C
但不熟悉Swift
。 What will be the issue in the code? 代码中的问题是什么?
Wrong addConstraints()
is being called. 错误的addConstraints()
被调用。
You're calling viewController.addConstraints()
when it appears you want to call view.addConstraints()
您要在调用viewController.addConstraints()
时要调用view.addConstraints()
Change the second addConstraints()
to view.addConstraints()
将第二个addConstraints()
更改为view.addConstraints()
It was also necessary to use Xcode version above 8.1. 还必须使用8.1以上的Xcode版本。
I have used the same code as yours. 我使用了与您相同的代码。 Just applied the constraints to view
and it works perfectly. 只需将约束应用于view
正常运行。
view.addConstraints([
(.centerX, center.x),
(.centerY, center.y)
].flatMap {
.init(item: view, attribute: $0, relatedBy: .equal, toItem: self, attribute: $0, multiplier: multiplier, constant: $1)
})
There is no issue in the flatMap
syntax. flatMap
语法没有问题。 I have executed the code on Xcode-9
as well as Xcode-8
and it doesn't give me any error. 我已经在Xcode-9
和Xcode-8
上执行了代码,但没有给我任何错误。
Just used the same code that I have written above and see if it compiles correctly. 只是使用了我上面编写的相同代码,然后看它是否可以正确编译。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.