<!--
{
  "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/Keys-swift.struct/starts(with:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:STsSQ7ElementRpzrlE6starts4withSbqd___tSTRd__AAQyd__ABRSlF::SYNTHESIZED::s:SD4KeysV"
  },
  "title" : "starts(with:)"
}
-->

# 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: PossiblePrefix) -> Bool where PossiblePrefix : Sequence, Self.Element == PossiblePrefix.Element
```

## Parameters

`possiblePrefix`

A sequence to compare to this sequence.

## Return Value

`true` if the initial elements of the sequence are the same as
the elements of `possiblePrefix`; otherwise, `false`. If
`possiblePrefix` has no elements, the return value is `true`.

## Discussion

This example tests whether one countable range begins with the elements
of another countable range.

```
let a = 1...3
let b = 1...10

print(b.starts(with: a))
// Prints "true"
```

Passing a sequence with no elements or an empty collection as
`possiblePrefix` always results in `true`.

```
print(b.starts(with: []))
// Prints "true"
```

> Complexity: O(*m*), where *m* is the lesser of the length of the
> sequence and the length of `possiblePrefix`.

---

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)