<!--
{
  "availability" : [
    "macOS: 13.3.0 -",
    "swift: 5.1.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSViewController/ViewLoading",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "s:So16NSViewControllerC6AppKitE11ViewLoadingV"
  },
  "title" : "NSViewController.ViewLoading"
}
-->

# NSViewController.ViewLoading

A property wrapper that loads the view controller’s view before accessing the property.

```
@propertyWrapper struct ViewLoading<Value>
```

## Overview

Use this property wrapper on view controller properties that can be `nil` before the view controller’s view loads. Wrapping view controller properties this way eliminates crashes that can occur from implicitly defining properties as <doc://com.apple.documentation/documentation/Swift/Optional>, and then referencing them before the view controller finishes loading.

The following example uses the `NSViewController.ViewLoading` wrapper to ensure that `dateLabel` [`NSTextField`](/documentation/AppKit/NSTextField) loads before referencing it in the `didSet` of the `date` property observer:

```swift
class DateViewController: NSViewController {
    @ViewLoading private var dateLabel: NSTextField
    
    var date: Date? {
        didSet {
            let dateFormatter = DateFormatter()
            dateFormatter.dateStyle = .full
            let dateString = dateFormatter.string(from: self.date ?? Date())
            self.dateLabel.stringValue = dateString
        }
    }
}
```

After loading [`NSTextField`](/documentation/AppKit/NSTextField), the system can safely access and set the `date` property.

```swift
let dateViewController = DateViewController()
dateViewController.date = Date()
```

Use this property wrapper over implicitly unwrapped optionals for `IBOutlets` as well.

```swift
@IBOutlet @ViewLoading private var dateLabel: NSTextField
```

## Topics

### Creating a ViewLoading Property Wrapper

[`init()`](/documentation/AppKit/NSViewController/ViewLoading/init())

Creates an empty property wrapper that loads the view controller’s view before accessing the property.

[`init(wrappedValue:)`](/documentation/AppKit/NSViewController/ViewLoading/init(wrappedValue:))

Creates a property wrapper that loads the view controller’s view before accessing the property.

## See Also

[`NSWindowController.WindowLoading`](/documentation/AppKit/NSWindowController/WindowLoading)

A property wrapper that loads the receiver’s window.



---

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)