用法一
實例方法
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(_:)。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。