<!--
{
  "documentType" : "article",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/order-dependent-operations-on-set",
  "metadataVersion" : "0.1.0",
  "role" : "collectionGroup",
  "title" : "Order Dependent Operations on Set"
}
-->

# Order Dependent Operations on Set

Perform order-dependent operations common to all collections, as implemented for
`Set`.

## Topics

### Manipulating Indices

[`var startIndex: Set<Element>.Index`](/documentation/Swift/Set/startIndex)

The starting position for iterating members of the set.

[`var endIndex: Set<Element>.Index`](/documentation/Swift/Set/endIndex)

The “past the end” position for the set—that is, the position one
greater than the last valid subscript argument.

[`func index(after: Set<Element>.Index) -> Set<Element>.Index`](/documentation/Swift/Set/index(after:))

Returns the position immediately after the given index.

[`func formIndex(after: inout Set<Element>.Index)`](/documentation/Swift/Set/formIndex(after:))

Replaces the given index with its successor.

[`func index(Self.Index, offsetBy: Int) -> Self.Index`](/documentation/Swift/Set/index(_:offsetBy:))

Returns an index that is the specified distance from the given index.

[`func formIndex(inout Self.Index, offsetBy: Int)`](/documentation/Swift/Set/formIndex(_:offsetBy:))

Offsets the given index by the specified distance.

[`func index(Self.Index, offsetBy: Int, limitedBy: Self.Index) -> Self.Index?`](/documentation/Swift/Set/index(_:offsetBy:limitedBy:))

Returns an index that is the specified distance from the given index,
unless that distance is beyond a given limiting index.

[`func formIndex(inout Self.Index, offsetBy: Int, limitedBy: Self.Index) -> Bool`](/documentation/Swift/Set/formIndex(_:offsetBy:limitedBy:))

Offsets the given index by the specified distance, or so that it equals
the given limiting index.

[`func distance(from: Self.Index, to: Self.Index) -> Int`](/documentation/Swift/Set/distance(from:to:))

Returns the distance between two indices.

[`var indices: DefaultIndices<Self>`](/documentation/Swift/Set/indices-swift.property)

The indices that are valid for subscripting the collection, in ascending
order.

### Comparing Sets

[`func elementsEqual<OtherSequence>(OtherSequence) -> Bool`](/documentation/Swift/Set/elementsEqual(_:))

Returns a Boolean value indicating whether this sequence and another
sequence contain the same elements in the same order.

[`func elementsEqual<OtherSequence>(OtherSequence, by: (Self.Element, OtherSequence.Element) throws -> Bool) rethrows -> Bool`](/documentation/Swift/Set/elementsEqual(_:by:))

Returns a Boolean value indicating whether this sequence and another
sequence contain equivalent elements in the same order, using the given
predicate as the equivalence test.

[`func lexicographicallyPrecedes<OtherSequence>(OtherSequence) -> Bool`](/documentation/Swift/Set/lexicographicallyPrecedes(_:))

Returns a Boolean value indicating whether the sequence precedes another
sequence in a lexicographical (dictionary) ordering, using the
less-than operator (`<`) to compare elements.

[`func lexicographicallyPrecedes<OtherSequence>(OtherSequence, by: (Self.Element, Self.Element) throws -> Bool) rethrows -> Bool`](/documentation/Swift/Set/lexicographicallyPrecedes(_:by:))

Returns a Boolean value indicating whether the sequence precedes another
sequence in a lexicographical (dictionary) ordering, using the given
predicate to compare elements.

[`func starts<PossiblePrefix>(with: PossiblePrefix) -> Bool`](/documentation/Swift/Set/starts(with:))

Returns a Boolean value indicating whether the initial elements of the
sequence are the same as the elements in another sequence.

[`func starts<PossiblePrefix>(with: PossiblePrefix, by: (Self.Element, PossiblePrefix.Element) throws -> Bool) rethrows -> Bool`](/documentation/Swift/Set/starts(with:by:))

Returns a Boolean value indicating whether the initial elements of the
sequence are equivalent to the elements in another sequence, using
the given predicate as the equivalence test.

### Selecting Elements

[`subscript(Set<Element>.Index) -> Element`](/documentation/Swift/Set/subscript(_:))

Accesses the member at the given position.

[`func prefix(Int) -> Self.SubSequence`](/documentation/Swift/Set/prefix(_:))

Returns a subsequence, up to the specified maximum length, containing
the initial elements of the collection.

[`func prefix(upTo: Self.Index) -> Self.SubSequence`](/documentation/Swift/Set/prefix(upTo:))

Returns a subsequence from the start of the collection up to, but not
including, the specified position.

[`func prefix(through: Self.Index) -> Self.SubSequence`](/documentation/Swift/Set/prefix(through:))

Returns a subsequence from the start of the collection through the
specified position.

[`func prefix(while: (Self.Element) throws -> Bool) rethrows -> Self.SubSequence`](/documentation/Swift/Set/prefix(while:))

Returns a subsequence containing the initial elements until `predicate`
returns `false` and skipping the remaining elements.

[`func suffix(Int) -> Self.SubSequence`](/documentation/Swift/Set/suffix(_:))

Returns a subsequence, up to the given maximum length, containing the
final elements of the collection.

[`func suffix(from: Self.Index) -> Self.SubSequence`](/documentation/Swift/Set/suffix(from:))

Returns a subsequence from the specified position to the end of the
collection.

### Excluding Elements

[`func drop(while: (Self.Element) throws -> Bool) rethrows -> Self.SubSequence`](/documentation/Swift/Set/drop(while:))

Returns a subsequence by skipping elements while `predicate` returns
`true` and returning the remaining elements.

[`func dropFirst(Int) -> Self.SubSequence`](/documentation/Swift/Set/dropFirst(_:))

Returns a subsequence containing all but the given number of initial
elements.

[`func dropLast(Int) -> Self.SubSequence`](/documentation/Swift/Set/dropLast(_:))

Returns a subsequence containing all but the specified number of final
elements.

[`func popFirst() -> Element?`](/documentation/Swift/Set/popFirst())

Removes and returns the first element of the set.

### Reversing a Set’s Elements

[`func reversed() -> [Self.Element]`](/documentation/Swift/Set/reversed())

Returns an array containing the elements of this sequence in reverse
order.

### Splitting and Joining Elements

[`func joined() -> FlattenSequence<Self>`](/documentation/Swift/Set/joined())

Returns the elements of this sequence of sequences, concatenated.

[`func joined<Separator>(separator: Separator) -> JoinedSequence<Self>`](/documentation/Swift/Set/joined(separator:)-7ubey)

Returns the concatenated elements of this sequence of sequences,
inserting the given separator between each element.

[`func joined(separator: String) -> String`](/documentation/Swift/Set/joined(separator:)-1cko4)

Returns a new string by concatenating the elements of the sequence,
adding the given separator between each element.

[`func split(separator: Self.Element, maxSplits: Int, omittingEmptySubsequences: Bool) -> [Self.SubSequence]`](/documentation/Swift/Set/split(separator:maxSplits:omittingEmptySubsequences:))

Returns the longest possible subsequences of the collection, in order,
around elements equal to the given element.

[`func split(maxSplits: Int, omittingEmptySubsequences: Bool, whereSeparator: (Self.Element) throws -> Bool) rethrows -> [Self.SubSequence]`](/documentation/Swift/Set/split(maxSplits:omittingEmptySubsequences:whereSeparator:))

Returns the longest possible subsequences of the collection, in order,
that don’t contain elements satisfying the given predicate.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)