Instance Method

reserveCapacity(_:)

Reserves enough space in the string’s underlying storage to store the specified number of ASCII characters.

Declaration

mutating func reserveCapacity(_ n: Int)

Parameters

n

The minimum number of ASCII character’s worth of storage to allocate.

Discussion

Because each character in a string can require more than a single ASCII character’s worth of storage, additional allocation may be necessary when adding characters to a string after a call to reserveCapacity(_:).

Complexity: O(n)

Relationships

See Also

Appending Strings and Characters

func append(String)

Appends the given string to this string.

func append(Character)

Appends the given character to the string.

func append<S>(contentsOf: S)

Appends the characters in the given sequence to the string.

func append<S>(contentsOf: S)

Adds the elements of a sequence or collection to the end of this collection.

static func + <Other>(Other, String) -> String

Creates a new collection by concatenating the elements of a sequence and a collection.

static func + <Other>(String, Other) -> String

Creates a new collection by concatenating the elements of a collection and a sequence.

static func + <Other>(String, Other) -> String

Creates a new collection by concatenating the elements of two collections.

static func += <Other>(inout String, Other)

Appends the elements of a sequence to a range-replaceable collection.