<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/Dictionary/popFirst()",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:SD8popFirstx3key_q_5valuetSgyF"
  },
  "title" : "popFirst()"
}
-->

# popFirst()

Removes and returns the first key-value pair of the dictionary if the
dictionary isn’t empty.

```
mutating func popFirst() -> Dictionary<Key, Value>.Element?
```

## Return Value

The first key-value pair of the dictionary if the dictionary
is not empty; otherwise, `nil`.

## Discussion

The first element of the dictionary is not necessarily the first element
added. Don’t expect any particular ordering of key-value pairs.

> Complexity: Averages to O(1) over many calls to `popFirst()`.

---

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)