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

# setValue(_:forComponent:)

Sets a value for a given calendar unit.

## Declaration

```swift
func setValue(_ value: Int, forComponent unit: NSCalendar.Unit)
```

## Parameters

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

## Discussion

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

## See Also

### Accessing Components as Calendrical Units

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