---
title: "setNilValueForKey(_:)"
framework: objectivec
role: symbol
role_heading: Instance Method
path: "objectivec/nsobject-swift.class/setnilvalueforkey(_:)"
---

# setNilValueForKey(_:)

Invoked by setValue(_:forKey:) when it’s given a nil value for a scalar value (such as an int or float).

## Declaration

```swift
func setNilValueForKey(_ key: String)
```

## Parameters

- `key`: The name of one of the receiver’s properties.

## Discussion

Discussion Subclasses can override this method to handle the request in some other way, such as by substituting 0 or a sentinel value for nil and invoking setValue(_:forKey:) again or setting the variable directly. The default implementation raises an NSInvalidArgumentException.

## See Also

### Setting Values

- [setValue(_:forKeyPath:)](objectivec/nsobject-swift.class/setvalue(_:forkeypath:).md)
- [setValuesForKeys(_:)](objectivec/nsobject-swift.class/setvaluesforkeys(_:).md)
- [setValue(_:forKey:)](objectivec/nsobject-swift.class/setvalue(_:forkey:).md)
- [setValue(_:forUndefinedKey:)](objectivec/nsobject-swift.class/setvalue(_:forundefinedkey:).md)
