<!--
{
  "availability" : [
    "iOS: 27.0.0 -",
    "iPadOS: 27.0.0 -",
    "macOS: 27.0.0 -",
    "visionOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "PaperKit",
  "identifier" : "/documentation/PaperKit/MarkupOrderedSet",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "PaperKit"
    ],
    "preciseIdentifier" : "s:8PaperKit16MarkupOrderedSetV"
  },
  "title" : "MarkupOrderedSet"
}
-->

# MarkupOrderedSet

An ordered set of markup elements.

```
struct MarkupOrderedSet
```

## Overview

The set ensures all elements have unique `id` values.

## Topics

### Creating a set

[`init()`](/documentation/PaperKit/MarkupOrderedSet/init())

Creates a new, empty collection.

### Adding elements

[`func append(MarkupOrderedSet.Element) -> (inserted: Bool, index: Int)`](/documentation/PaperKit/MarkupOrderedSet/append(_:))

Appends a new member to the end of the set, if the set doesn’t already contain it.

[`func append(contentsOf: some Sequence<any Markup>)`](/documentation/PaperKit/MarkupOrderedSet/append(contentsOf:))

Appends the contents of a sequence to the end of the set, excluding elements that are already members.

[`func insert(MarkupOrderedSet.Element, at: Int) -> (inserted: Bool, index: Int)`](/documentation/PaperKit/MarkupOrderedSet/insert(_:at:))

Inserts a new member at the specified index, if the set doesn’t already contain it.

[`func updateOrAppend(MarkupOrderedSet.Element) -> MarkupOrderedSet.Element?`](/documentation/PaperKit/MarkupOrderedSet/updateOrAppend(_:))

Adds the given element to the set unconditionally, either appending it to the set, or replacing
an existing value if one with the same id is present.

### Accessing elements

[`subscript(UUID) -> PKStroke?`](/documentation/PaperKit/MarkupOrderedSet/subscript(_:)-1h73t)

Accesses the stroke for the given id.

[`subscript<T>(MarkupID<T>) -> T?`](/documentation/PaperKit/MarkupOrderedSet/subscript(_:)-6e2ez)

Accesses the element for the given id.

[`subscript(MarkupOrderedSet.ElementID) -> MarkupOrderedSet.Element?`](/documentation/PaperKit/MarkupOrderedSet/subscript(_:)-79x8r)

Accesses the element for the given id.

[`var ids: MarkupOrderedSet.ElementIDs`](/documentation/PaperKit/MarkupOrderedSet/ids)

A view of the set’s element ids.

[`var strokes: [PKStroke]`](/documentation/PaperKit/MarkupOrderedSet/strokes)

The strokes in the set.

[`var count: Int`](/documentation/PaperKit/MarkupOrderedSet/count)

The number of elements in the set.

### Removing elements

[`func remove(MarkupOrderedSet.Element) -> MarkupOrderedSet.Element?`](/documentation/PaperKit/MarkupOrderedSet/remove(_:))

Removes the given element from the set.

[`func remove(at: Int) -> MarkupOrderedSet.Element`](/documentation/PaperKit/MarkupOrderedSet/remove(at:))

Removes and returns the element at the specified position.

[`func removeAll(where: (MarkupOrderedSet.Element) throws -> Bool) rethrows`](/documentation/PaperKit/MarkupOrderedSet/removeAll(where:))

Removes all the elements that satisfy the given predicate.

[`func removeElement<T>(for: MarkupID<T>) -> T?`](/documentation/PaperKit/MarkupOrderedSet/removeElement(for:)-4pqof)

Removes the associated element for the given id from the set.

[`func removeElement(for: MarkupOrderedSet.ElementID) -> MarkupOrderedSet.Element?`](/documentation/PaperKit/MarkupOrderedSet/removeElement(for:)-5khjd)

Removes the associated element for the given id from the set.

[`func removeStroke(for: UUID) -> PKStroke?`](/documentation/PaperKit/MarkupOrderedSet/removeStroke(for:))

Removes the associated stroke for the given id from the set.

### Finding elements

[`func contains(MarkupOrderedSet.Element) -> Bool`](/documentation/PaperKit/MarkupOrderedSet/contains(_:))

Returns a Boolean value that indicates whether the given element exists in the set.

[`func firstIndex(of: MarkupOrderedSet.Element) -> Int?`](/documentation/PaperKit/MarkupOrderedSet/firstIndex(of:))

Returns the index of the given element in the set, or `nil` if the element is not a member
of the set.

### Identifying elements

[`enum ElementID`](/documentation/PaperKit/MarkupOrderedSet/ElementID)

The markup ID types supported in a markup ordered set.

[`struct ElementIDs`](/documentation/PaperKit/MarkupOrderedSet/ElementIDs)

A view of a set’s ids.

[`typealias Element`](/documentation/PaperKit/MarkupOrderedSet/Element)

The type of element in the set.

### Default Implementations

[BidirectionalCollection Implementations](/documentation/PaperKit/MarkupOrderedSet/BidirectionalCollection-Implementations)

[Collection Implementations](/documentation/PaperKit/MarkupOrderedSet/Collection-Implementations)

## Relationships

### Conforms To

[`RandomAccessCollection`](/documentation/Swift/RandomAccessCollection)

[`Sendable`](/documentation/Swift/Sendable)

[`Copyable`](/documentation/Swift/Copyable)

[`Collection`](/documentation/Swift/Collection)

[`Escapable`](/documentation/Swift/Escapable)

[`Sequence`](/documentation/Swift/Sequence)

[`BidirectionalCollection`](/documentation/Swift/BidirectionalCollection)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

---

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)