使用此代码,我在调用Swift Xcode-beta时得到了错误的额外参数。
self.blendShapeLabel.text = "The blendshapes are ((format: "%.2f"), eyeBlinkR),((format: "%.2f"), eyeBlinkL),((format: "%.2f"), eyeLookInL),((format: "%.2f"), eyeLookInR),((format: "%.2f"), eyeLookOutL),((format: "%.2f"), eyeLookOutR),((format: "%.2f"), eyeLookDownL),((format: "%.2f"), eyeLookDownR),((format: "%.2f"), eyeLookUpL),((format: "%.2f"), eyeLookUpR),((format: "%.2f"), eyeSquintL),((format: "%.2f"), eyeWideL),((format: "%.2f"), eyeSquintR),((format: "%.2f"), eyeWideR),((format: "%.2f"), mouthL),((format: "%.2f"), mouthR),((format: "%.2f"), mouthFrownL),((format: "%.2f"), mouthFrownR),((format: "%.2f"), mouthSmileL),((format: "%.2f"), mouthSmileR),((format: "%.2f"), mouthDimpleL),((format: "%.2f"), mouthDimpleR),((format: "%.2f"), mouthStretchL),((format: "%.2f"), mouthStretchR),((format: "%.2f"), mouthCloseCoeff),((format: "%.2f"), mouthPucker),((format: "%.2f"), mouthFunnel),((format: "%.2f"), mouthRollLower),((format: "%.2f"), mouthRollUpper),((format: "%.2f"), mouthPressL),((format: "%.2f"), mouthPressR),((format: "%.2f"), mouthLowerDownL),((format: "%.2f"), mouthLowerDownR),((format: "%.2f"), mouthUpperUpL),((format: "%.2f"), mouthUpperUpR),((format: "%.2f"), jawForward),((format: "%.2f"), jawLeft),((format: "%.2f"), jawRight),((format: "%.2f"), jawOpen),((format: "%.2f"), cheekPuff),((format: "%.2f"), cheekSquintL),((format: "%.2f"), cheekSquintR),((format: "%.2f"), noseSneerL),((format: "%.2f"), noseSneerR),((format: "%.2f"), tongueOut),((format: "%.2f"), browInnerUp),((format: "%.2f"), browDownL),((format: "%.2f"), browDownR),((format: "%.2f"), browOutterL),((format: "%.2f"), browOutterR)."
我不知道你想用format:
执行什么样的格式化,相反,我建议使用formatted()
和FormatStyle
假设您的值为Double
类型,我们创建一个自定义格式样式
let dec2: FloatFormatStyle<Double> = .number.precision(.fractionLength(2))
,然后在创建字符串时使用它(示例为了简洁而缩短)
"The blendshapes are (eyeBlinkR.formatted(dec2)),(eyeBlinkL.formatted(dec2))."
完整的示例
let eyeBlinkR = 1.123
let eyeBlinkL = 1.456
let dec2: FloatFormatStyle<Float> = .number.precision(.fractionLength(2))
let out = "The blendshapes are (eyeBlinkR.formatted(dec2)),(eyeBlinkL.formatted(dec2))."
print(out)
blendshapes分别为1.12,1.46.