當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Swift Unicode.UTF16 trailSurrogate(_:)用法及代碼示例

類型方法

trailSurrogate(_:)

返回表示指定 Unicode 標量的代理對的低代理代碼單元。

聲明

static func trailSurrogate(_ x: Unicode.Scalar) -> UTF16.CodeUnit

返回值

x 以 UTF-16 編碼時的尾隨代理代碼單元。

參數

x

一個 Unicode 標量值。 x 在以 UTF-16 編碼時必須由代理對表示。要檢查 x 是否由代理對表示,請使用 UTF16.width(x) == 2

詳述

由於 Unicode 標量值最多需要 21 位來存儲其值,因此某些 Unicode 標量在 UTF-16 中由一對 16 位代碼單元表示。該對的第一個和第二個代碼單元,指定為 leadingtrailing 代理,組成一個 surrogate pair


let apple: Unicode.Scalar = "🍎"
print(UTF16.trailSurrogate(apple))
// Prints "57166"

可用版本

iOS 8.0+, iPadOS 8.0+, macOS 10.10+, Mac Catalyst 13.0+, tvOS 9.0+, watchOS 2.0+

相關用法


注:本文由純淨天空篩選整理自apple.com大神的英文原創作品 Unicode.UTF16 trailSurrogate(_:)。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。