How to fix “Expression type '@lvalue CGRect/CGSize' is ambiguous without more context”?

南楼画角 提交于 2019-12-23 06:24:08

问题


I have an existing codebase that was written in Swift 3 and Xcode 9 that I am having trouble migrating to Xcode 10 and Swift 4.2 due to build errors within the code.

The problem I am running into now is this:

"Expression type '@lvalue CGRect' is ambiguous without more context"

I am getting this error in 3 different areas of my code. The fourth one is related but different in that it says:

"Expression type '(CGSize) -> CGSize' is ambiguous without more context"

I have tried changing all values within the expression to explicitly use the data type CGFloat to remove any inferred data type errors, and this still did not fix the problem.

 override func sizeThatFits(_ size: CGSize) -> CGSize {
    let adjustedHeight = 8.0 + titleLabel.frame.height + 2.0 + underlineView.frame.height
    adjustedHeight += 16.0 + mapImageView.frame.height + 16.0
    return CGSize(width: bounds.width, height: adjustedHeight)
}

override func sizeThatFits(_ size: CGSize) -> CGSize {
    let adjustedHeight = 10.0 + titleLabel.frame.height + 15.0 + daysRoundedView.frame.height
    adjustedHeight += daysTextLabel.frame.height + 10.0 + logoImageView.frame.height + 20.0
    return CGSize(width: size.width, height: adjustedHeight)
}

override func sizeThatFits(_ size: CGSize) -> CGSize {
    let adjustedHeight = 8.0 + titleLabel.frame.height + 2.0
    adjustedHeight += underlineView.frame.height + 16.0 + flyerImageView.frame.height + 16.0
    return CGSize(width: bounds.width, height: adjustedHeight)
}

override func sizeThatFits(_ size: CGSize) -> CGSize {
    let adjustedHeight = 8.0 + titleLabel.frame.height + 2.0 +  underlineView.frame.height + 16.0
    adjustedHeight += descriptionTextView.sizeThatFits(CGSize(width: size.width - 40, height: size.height)).height + 16.0
    return CGSize(width: bounds.width, height: adjustedHeight)
}

The issue is with the adjustedHeight variable. I'm not sure if a different function or syntax is used in Swift 4.2 for this but I cannot seem to fix this error.


回答1:


One of the issues is that adjustedHeight is a let, but it's being modified in the next line with the += operator. Does the issue get fixed after you change adjustedHeight to var?



来源:https://stackoverflow.com/questions/54464103/how-to-fix-expression-type-lvalue-cgrect-cgsize-is-ambiguous-without-more-co

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!