---
title: "value(forComponent:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsdatecomponents/value(forcomponent:)"
---

# value(forComponent:)

Returns the value for a given calendar unit.

## Declaration

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

## Parameters

- `unit`: The calendar unit for which to retrieve its value. Do not pass doc://com.apple.foundation/documentation/Foundation/NSCalendar/Unit/calendar or doc://com.apple.foundation/documentation/Foundation/NSCalendar/Unit/timeZone.

## Return Value

Return Value The value for the given calendar unit.

## Discussion

Discussion This method allows for component values to be retrieved for an NSCalendar.Unit value.

## See Also

### Accessing Components as Calendrical Units

- [setValue(_:forComponent:)](foundation/nsdatecomponents/setvalue(_:forcomponent:).md)
- [NSCalendar.Unit](foundation/nscalendar/unit.md)
