gpt4 book ai didi

ios - 在 swift 中使用 stringInterpolationSegment 字符串初始值设定项

转载 作者:搜寻专家 更新时间:2023-11-01 07:22:03 24 4
gpt4 key购买 nike

在研究来自 Apple 的字符串结构引用时 (String Structure Reference)

有接受 Int 参数的初始化方法,例如:

init(stringInterpolationSegment expr: Int)

我尝试通过编写下面的代码来学习如何使用它,并了解按引用传递与按值传递之间的区别,但无法使用以下代码使其工作:

struct Soho {
var myCountry = "America"
init(stringInterpolationSegment expr: Int){

}

}

为了使用这个字符串初始化器,swift 代码应该如何构建?

最佳答案

来自 https://developer.apple.com/reference/swift/string/1539185-init ,苹果说:

Creates a string containing the given value’s textual representation.

Do not call this initializer directly. It is used by the compiler when interpreting string interpolations.

(强调我的)

他们在 https://developer.apple.com/reference/swift/stringinterpolationconvertible 中向您展示了一个示例,我们看到我们确实应该使用带有 "\()" 的字符串插值。

关于ios - 在 swift 中使用 stringInterpolationSegment 字符串初始值设定项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38354864/

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