<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSStatusBar/statusItem(withLength:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSStatusBar(im)statusItemWithLength:"
  },
  "title" : "statusItem(withLength:)"
}
-->

# statusItem(withLength:)

Returns a newly created status item that has been allotted a specified space within the status bar.

```
func statusItem(withLength length: CGFloat) -> NSStatusItem
```

## Parameters

`length`

A constant that specifies whether the status item is of fixed width, or variable width. The valid constants are described in [Status Bar Item Length](/documentation/AppKit/status-bar-item-length).

## Return Value

An [`NSStatusItem`](/documentation/AppKit/NSStatusItem) object.

## Discussion

The receiver does not retain a reference to the status item, so you need to retain it. Otherwise, the object is removed from the status bar when it is deallocated.

---

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)