<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.9.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSDateComponents/value(forComponent:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSDateComponents(im)valueForComponent:"
  },
  "title" : "value(forComponent:)"
}
-->

# value(forComponent:)

Returns the value for a given calendar unit.

```
func value(forComponent unit: NSCalendar.Unit) -> Int
```

## Parameters

`unit`

The calendar unit for which to retrieve its value. Do not pass [`calendar`](/documentation/Foundation/NSCalendar/Unit/calendar) or [`timeZone`](/documentation/Foundation/NSCalendar/Unit/timeZone).

## Return Value

The value for the given calendar unit.

## Discussion

This method allows for component values to be retrieved for an [`NSCalendar.Unit`](/documentation/Foundation/NSCalendar/Unit) value.

---

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)