typealias StaticString.ExtendedGraphemeClusterLiteralType
typealias StaticString.StringLiteralType
typealias StaticString.UnicodeScalarLiteralType
Availability
Technology
@frozen struct StaticString
Instances of the Static
type are immutable.
Static
型のインスタンスは、不変です。
Static
provides only low-level access to its contents, unlike Swift’s more commonly used String
type. A static string can use either of the following as its storage:
Static
は、それの内容への低レベルアクセスのみを提供します、Swiftのもつより一般的に使われるString
型とは違って。静的文字列は、以下のどちらかをそれのストレージとして使用できます:
a pointer to a null-terminated sequence of UTF-8 code units: null終端された一連のUTF-8コード単位へのあるポインタ:
let emoji: StaticString = "\u{1F600}"
emoji.hasPointerRepresentation //-> true
emoji.isASCII //-> false
emoji.unicodeScalar //-> Fatal error!
emoji.utf8CodeUnitCount //-> 4
emoji.utf8Start[0] //-> 0xF0
emoji.utf8Start[1] //-> 0x9F
emoji.utf8Start[2] //-> 0x98
emoji.utf8Start[3] //-> 0x80
emoji.utf8Start[4] //-> 0x00
a single Unicode scalar value, under very limited circumstances: 単一のユニコードスカラー値、非常に制限された状況のもとで:
struct MyStaticScalar: ExpressibleByUnicodeScalarLiteral {
typealias UnicodeScalarLiteralType = StaticString
let value: StaticString
init(unicodeScalarLiteral value: StaticString) {
self.value = value
}
}
let emoji: StaticString = MyStaticScalar("\u{1F600}").value
emoji.hasPointerRepresentation //-> false
emoji.isASCII //-> false
emoji.unicodeScalar.value //-> 0x1F600
emoji.utf8CodeUnitCount //-> Fatal error!
emoji.utf8Start //-> Fatal error!
You can use the with
method to access a static string’s contents, regardless of which representation the static string uses.
あなたは、with
メソッドを使うことで、静的文字列のもつ内容にアクセスできます、その静的文字列が使うのはどの表現かに関係なく。
emoji.withUTF8Buffer { utf8 in
utf8.count //-> 4
utf8[0] //-> 0xF0
utf8[1] //-> 0x9F
utf8[2] //-> 0x98
utf8[3] //-> 0x80
utf8[4] //-> Fatal error!
}
typealias StaticString.ExtendedGraphemeClusterLiteralType
typealias StaticString.StringLiteralType
typealias StaticString.UnicodeScalarLiteralType
init()
init(extendedGraphemeClusterLiteral : StaticString)
init(stringLiteral : StaticString)
init(unicodeScalarLiteral : StaticString)
var customMirror : Mirror
var debugDescription : String
var description: String
var hasPointerRepresentation : Bool
var isASCII : Bool
var unicodeScalar : Unicode.Scalar
var utf8CodeUnitCount : Int
var utf8Start: UnsafePointer<UInt8>
func withUTF8Buffer <R>((UnsafeBufferPointer<UInt8>) -> R) -> R