<!--
{
  "availability" : [
    "macOS: 12.0.0 -",
    "tvOS: 14.0.0 -",
    "watchOS: 7.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/View/focusScope(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI4ViewPAAE10focusScopeyQrAA9NamespaceV2IDVF"
  },
  "title" : "focusScope(_:)"
}
-->

# focusScope(_:)

Creates a focus scope that SwiftUI uses to limit default focus
preferences.

```
nonisolated func focusScope(_ namespace: Namespace.ID) -> some View
```

## Parameters

`namespace`

A namespace identifier that SwiftUI can use to scope
default focus preferences.

## Return Value

A view that sets the namespace of descendants for default
focus.

## Discussion

The returned view gets associated with the provided namespace.
Pass this namespace to [`prefersDefaultFocus(_:in:)`](/documentation/SwiftUI/View/prefersDefaultFocus(_:in:)) and
the [`resetFocus`](/documentation/SwiftUI/EnvironmentValues/resetFocus) function.

---

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)