用法一
实例方法
append
appendInterpolation(_:)
将给定值的文本表示插入到正在创建的字符串文字中。
声明
mutating func appendInterpolation<T>(_ value: T) where T : CustomStringConvertible, T : TextOutputStreamable
详述
不要直接调用此方法。编译器在解释字符串插值时使用它。相反,使用字符串插值来创建一个新字符串,方法是在括号中包含值、文字、变量或表达式,并以反斜杠 (\(
... )
) 为前缀。
let price = 2
let number = 3
let message = """
If one cookie costs \(price) dollars, \
\(number) cookies cost \(price * number) dollars.
"""
print(message)
// Prints "If one cookie costs 2 dollars, 3 cookies cost 6 dollars."
可用版本
iOS 8.0+, iPadOS 8.0+, macOS 10.10+, Mac Catalyst 13.0+, tvOS 9.0+, watchOS 2.0+
用法二
实例方法
append
appendInterpolation(_:)
将给定值的文本表示插入到正在创建的字符串文字中。
声明
mutating func appendInterpolation<T>(_ value: T) where T : TextOutputStreamable
详述
不要直接调用此方法。编译器在解释字符串插值时使用它。相反,使用字符串插值来创建一个新字符串,方法是在括号中包含值、文字、变量或表达式,并以反斜杠 (\(
... )
) 为前缀。
let price = 2
let number = 3
let message = "If one cookie costs \(price) dollars, " +
"\(number) cookies cost \(price * number) dollars."
print(message)
// Prints "If one cookie costs 2 dollars, 3 cookies cost 6 dollars."
可用版本
iOS 8.0+, iPadOS 8.0+, macOS 10.10+, Mac Catalyst 13.0+, tvOS 9.0+, watchOS 2.0+
用法三
实例方法
append
appendInterpolation(_:)
将给定值的文本表示插入到正在创建的字符串文字中。
声明
mutating func appendInterpolation<T>(_ value: T) where T : CustomStringConvertible
详述
不要直接调用此方法。编译器在解释字符串插值时使用它。相反,使用字符串插值来创建一个新字符串,方法是在括号中包含值、文字、变量或表达式,并以反斜杠 (\(
... )
) 为前缀。
let price = 2
let number = 3
let message = """
If one cookie costs \(price) dollars, \
\(number) cookies cost \(price * number) dollars.
"""
print(message)
// Prints "If one cookie costs 2 dollars, 3 cookies cost 6 dollars."
可用版本
iOS 8.0+, iPadOS 8.0+, macOS 10.10+, Mac Catalyst 13.0+, tvOS 9.0+, watchOS 2.0+
用法四
实例方法
append
appendInterpolation(_:)
将给定值的文本表示插入到正在创建的字符串文字中。
声明
mutating func appendInterpolation<T>(_ value: T)
详述
不要直接调用此方法。编译器在解释字符串插值时使用它。相反,使用字符串插值来创建一个新字符串,方法是在括号中包含值、文字、变量或表达式,并以反斜杠 (\(
... )
) 为前缀。
let price = 2
let number = 3
let message = """
If one cookie costs \(price) dollars, \
\(number) cookies cost \(price * number) dollars.
"""
print(message)
// Prints "If one cookie costs 2 dollars, 3 cookies cost 6 dollars."
可用版本
iOS 8.0+, iPadOS 8.0+, macOS 10.10+, Mac Catalyst 13.0+, tvOS 9.0+, watchOS 2.0+
相关用法
- Swift DefaultStringInterpolation description用法及代码示例
- Swift DefaultStringInterpolation用法及代码示例
- Swift DefaultIndices endIndex用法及代码示例
- Swift DefaultIndices index(_:offsetBy:limitedBy:)用法及代码示例
- Swift DefaultIndices prefix(through:)用法及代码示例
- Swift DefaultIndices reduce(_:_:)用法及代码示例
- Swift DefaultIndices min(by:)用法及代码示例
- Swift DefaultIndices allSatisfy(_:)用法及代码示例
- Swift DefaultIndices shuffled()用法及代码示例
- Swift DefaultIndices shuffled(using:)用法及代码示例
- Swift DefaultIndices first用法及代码示例
- Swift DefaultIndices prefix(_:)用法及代码示例
- Swift DefaultIndices lexicographicallyPrecedes(_:)用法及代码示例
- Swift DefaultIndices index(_:offsetBy:)用法及代码示例
- Swift DefaultIndices compactMap(_:)用法及代码示例
- Swift DefaultIndices suffix(_:)用法及代码示例
- Swift DefaultIndices dropLast(_:)用法及代码示例
- Swift DefaultIndices last(where:)用法及代码示例
- Swift DefaultIndices filter(_:)用法及代码示例
- Swift DefaultIndices lastIndex(of:)用法及代码示例
- Swift DefaultIndices contains(_:)用法及代码示例
- Swift DefaultIndices max(by:)用法及代码示例
- Swift DefaultIndices prefix(upTo:)用法及代码示例
- Swift DefaultIndices split(separator:maxSplits:omittingEmptySubsequences:)用法及代码示例
- Swift DefaultIndices contains(where:)用法及代码示例
注:本文由纯净天空筛选整理自apple.com大神的英文原创作品 DefaultStringInterpolation appendInterpolation(_:)。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。