Protocol

StringProtocol

A type that can represent a string as a collection of characters.

Declaration

protocol StringProtocol where Self.Element == Character, Self.SubSequence : StringProtocol

Overview

Do not declare new conformances to StringProtocol. Only the String and Substring types in the standard library are valid conforming types.

Topics

Initializers

init(cString: UnsafePointer<CChar>)

Creates a string from the null-terminated, UTF-8 encoded sequence of bytes at the given pointer.

Required.

init<C, Encoding>(decoding: C, as: Encoding.Type)

Creates a string from the given Unicode code units in the specified encoding.

Required.

init<Encoding>(decodingCString: UnsafePointer<Encoding.CodeUnit>, as: Encoding.Type)

Creates a string from the null-terminated sequence of bytes at the given pointer.

Required.

Instance Properties

var capitalized: String
var decomposedStringWithCanonicalMapping: String
var decomposedStringWithCompatibilityMapping: String
var fastestEncoding: String.Encoding
var hash: Int
var localizedCapitalized: String
var localizedLowercase: String
var localizedUppercase: String
var precomposedStringWithCanonicalMapping: String
var precomposedStringWithCompatibilityMapping: String
var removingPercentEncoding: String?
var smallestEncoding: String.Encoding

Instance Methods

func appending<T>(T) -> String
func appendingFormat<T>(T, CVarArg...) -> String
func cString(using: String.Encoding) -> [CChar]?
func canBeConverted(to: String.Encoding) -> Bool
func capitalized(with: Locale?) -> String
func caseInsensitiveCompare<T>(T) -> ComparisonResult
func components(separatedBy: CharacterSet) -> [String]
func components<T>(separatedBy: T) -> [String]
func contains<T>(T) -> Bool
func hasPrefix(String) -> Bool

Required. Default implementation provided.

func hasSuffix(String) -> Bool

Required. Default implementation provided.

func lengthOfBytes(using: String.Encoding) -> Int
func lineRange<R>(for: R) -> Range<Self.Index>
func localizedCaseInsensitiveContains<T>(T) -> Bool
func localizedCompare<T>(T) -> ComparisonResult
func localizedStandardCompare<T>(T) -> ComparisonResult
func localizedStandardContains<T>(T) -> Bool
func lowercased(with: Locale?) -> String
func paragraphRange<R>(for: R) -> Range<Self.Index>
func propertyList() -> Any
func substring(from: Self.Index) -> String
Deprecated
func substring(to: Self.Index) -> String
Deprecated
func substring(with: Range<Self.Index>) -> String
Deprecated
func trimmingCharacters(in: CharacterSet) -> String
func uppercased(with: Locale?) -> String
func withCString<Result>((UnsafePointer<CChar>) -> Result) -> Result

Calls the given closure with a pointer to the contents of the string, represented as a null-terminated sequence of UTF-8 code units.

Required.

func withCString<Result, Encoding>(encodedAs: Encoding.Type, (UnsafePointer<Encoding.CodeUnit>) -> Result) -> Result

Calls the given closure with a pointer to the contents of the string, represented as a null-terminated sequence of code units.

Required.

Operator Functions

static func == <S>(Self, S) -> Bool

Returns a Boolean value indicating whether two values are equal.

See Also

Related String Types

struct Substring

A slice of a string.

struct String.Index

A position of a character or code unit in a string.

struct String.UnicodeScalarView

A view of a string’s contents as a collection of Unicode scalar values.

struct String.UTF16View

A view of a string’s contents as a collection of UTF-16 code units.

struct String.UTF8View

A view of a string’s contents as a collection of UTF-8 code units.