<!--
{
  "availability" : [
    "iOS: 17.0.0 -",
    "iPadOS: 17.0.0 -",
    "macCatalyst: 17.0.0 -",
    "macOS: 13.0.0 -",
    "tvOS: 16.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 9.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/View/defaultFocus(_:_:priority:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI4ViewPAAE12defaultFocus__8priorityQrAA0E5StateV7BindingVyqd___G_qd__AA07DefaultE18EvaluationPriorityVtSHRd__lF"
  },
  "title" : "defaultFocus(_:_:priority:)"
}
-->

# defaultFocus(_:_:priority:)

Defines a region of the window in which default focus is evaluated by
assigning a value to a given focus state binding.

```
nonisolated func defaultFocus<V>(_ binding: FocusState<V>.Binding, _ value: V, priority: DefaultFocusEvaluationPriority = .automatic) -> some View where V : Hashable
```

## Parameters

`binding`

A focus state binding to update when evaluating default
focus in the modified view hierarchy.

`value`

The value to set the binding to during evaluation.

`priority`

An indication of how to prioritize the preferred default
focus target when focus moves into the modified view hierarchy.
The default value is `automatic`, which means the preference will
be given priority when focus is being initialized or relocated
programmatically, but not when responding to user-directed
navigation commands.

## Return Value

The modified view.

## Discussion

By default, SwiftUI evaluates default focus when the window first
appears, and when a focus state binding update moves focus
automatically, but not when responding to user-driven navigation
commands.

Clients can override the default behavior by specifying an evaluation
priority of [`userInitiated`](/documentation/SwiftUI/DefaultFocusEvaluationPriority/userInitiated), which
causes SwiftUI to use the client’s preferred default focus in response
to user-driven focus navigation as well as automatic changes.

In the following example, focus automatically goes to the second of the
two text fields when the view is first presented in the window.

```
WindowGroup {
    VStack {
        TextField(...)
            .focused($focusedField, equals: .firstField)
        TextField(...)
            .focused($focusedField, equals: .secondField)
    }
    .defaultFocus($focusedField, .secondField)
}
```

---

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)