<!--
{
  "availability" : [
    "iOS: 16.4.0 -",
    "iPadOS: 16.4.0 -",
    "macCatalyst: -",
    "swift: 5.1.0 -",
    "tvOS: 16.4.0 -",
    "visionOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UIViewController/ViewLoading",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "s:So16UIViewControllerC5UIKitE11ViewLoadingV"
  },
  "title" : "UIViewController.ViewLoading"
}
-->

# UIViewController.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 [`UIViewController.ViewLoading`](/documentation/UIKit/UIViewController/ViewLoading) wrapper to ensure that `dateLabel` [`UILabel`](/documentation/UIKit/UILabel) loads before referencing it in the `didSet` of the `date` property observer:

```swift
class DateViewController: UIViewController {
    @ViewLoading private var dateLabel: UILabel
    
    var date: Date? {
        didSet {
            let dateFormatter = DateFormatter()
            dateFormatter.dateStyle = .full
            let dateString = dateFormatter.string(from: self.date ?? Date())
            // If the view controller's view hasn't loaded yet,
            // accessing the dateLabel property here causes it to load.
            self.dateLabel.text = dateString
        }
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        let label = UILabel(frame: self.view.bounds)
        self.view.addSubview(label)
        self.dateLabel = label
    }
}
```

After loading [`UILabel`](/documentation/UIKit/UILabel), 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: UILabel
```

## Topics

### Creating a ViewLoading property wrapper

[`init()`](/documentation/UIKit/UIViewController/ViewLoading/init())

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

[`init(wrappedValue:)`](/documentation/UIKit/UIViewController/ViewLoading/init(wrappedValue:))

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



---

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)