<!--
{
  "availability" : [
    "macCatalyst: 14.0.0 -",
    "macOS: 10.1.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "PreferencePanes",
  "identifier" : "/documentation/PreferencePanes/NSPreferencePane/assignMainView()",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Preference Panes"
    ],
    "preciseIdentifier" : "c:objc(cs)NSPreferencePane(im)assignMainView"
  },
  "title" : "assignMainView()"
}
-->

# assignMainView()

Locates and assigns the preference pane’s main view from the nib file loaded by [`loadMainView()`](/documentation/PreferencePanes/NSPreferencePane/loadMainView()).

```
func assignMainView()
```

## Discussion

The default implementation sets the receiver’s main view to the content view of the window referenced by the `_window` outlet. Before returning, [`assignMainView()`](/documentation/PreferencePanes/NSPreferencePane/assignMainView()) releases the window and sets the `_window` outlet to `nil`. Returns the main view if successful, `nil` otherwise.

Override this method if your main view is located in the nib file loaded by [`loadMainView()`](/documentation/PreferencePanes/NSPreferencePane/loadMainView()), but is not the content view of a window in the file. Call [`NSPreferencePane`](/documentation/PreferencePanes/NSPreferencePane) to set the main view of the preference pane before returning. Also call [`NSPreferencePane`](/documentation/PreferencePanes/NSPreferencePane), [`NSPreferencePane`](/documentation/PreferencePanes/NSPreferencePane), and [`NSPreferencePane`](/documentation/PreferencePanes/NSPreferencePane) to set the initial, first, and last keyboard focus views, respectively.

---

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)