gpt4 book ai didi

ios - 将 CGFloat 变量连接到多行字符串时出错

转载 作者:可可西里 更新时间:2023-11-01 00:53:43 26 4
gpt4 key购买 nike

尝试将变量连接到多行字符串时出现奇怪的错误。

错误:找不到成员“convertFromStringInterpolationSegment”

func getOpeningHTML() -> String
{
let maxWidth:CGFloat = self.webView.frame.width

return
"<html>" +
"<head>" +
"<style type=\"text/css\">" +
"body {" +
"color: white;" +
"padding:12px;" +
"line-height:140%;" +
"}" +
"a:link {" +
"color: #32b3e3;" +
"}" +
"img {" +
"margin-top: 10px;" +
"margin-bottom: 10px;" +
"margin-right: 10px;" +
"padding:2px; float: left;" +
"clear: both;" +
"border: 1px solid #637981;" +
"max-width: \(maxWidth)px;" + // THIS LINE CAUSES THE ERROR
"}" +
"img[alt~='Clothing'] { display: none; }" +
"img[alt~='shop'] { display: none; }" +
"img[alt~='AppHidden'] { display: none; }" +
"</style>" +
"</head><body>"
}

编辑:解决方案:

let maxWidth:CGFloat = self.webView.frame.width

var html:String = "<html>"
html += "<head>"
html += "<style type=\"text/css\">"
html += "body {"
html += "color: white;"
html += "padding:12px;"
html += "line-height:140%;"
html += "}"
html += "a:link {"
html += "color: #32b3e3;"
html += "}"
html += "img {"
html += "margin-top: 10px;"
html += "margin-bottom: 10px;"
html += "margin-right: 10px;"
html += "padding:2px; float: left;"
html += "clear: both;"
html += "border: 1px solid #637981;"
html += "max-width: \(maxWidth)px;"
html += "}"
html += "img[alt~='Clothing'] { display: none; }"
html += "img[alt~='shop'] { display: none; }"
html += "img[alt~='AppHidden'] { display: none; }"
html += "</style>"
html += "</head><body>"
return html

最佳答案

swift 编译器已知存在长连接问题。最好设置一个变量并逐行进行连接:

var s = "<html>"
s += "<head>"
...
return s

关于ios - 将 CGFloat 变量连接到多行字符串时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25884203/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com