---
title: "removeObject(forKey:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsmutabledictionary/removeobject(forkey:)"
---

# removeObject(forKey:)

Removes a given key and its associated value from the dictionary.

## Declaration

```swift
func removeObject(forKey aKey: Any)
```

## Parameters

- `aKey`: The key to remove. important: Raises an doc://com.apple.foundation/documentation/Foundation/NSExceptionName/invalidArgumentException if aKey is nil.

## Discussion

Discussion Does nothing if aKey does not exist. For example, assume you have an archived dictionary that records the call letters and associated frequencies of radio stations. To remove an entry for a defunct station, you could write code similar to the following: NSMutableDictionary *stations = nil;   stations = [[NSMutableDictionary alloc]         initWithContentsOfFile: pathToArchive]; [stations removeObjectForKey:@"KIKT"];

## See Also

### Removing Entries From a Mutable Dictionary

- [removeAllObjects()](foundation/nsmutabledictionary/removeallobjects().md)
- [removeObjects(forKeys:)](foundation/nsmutabledictionary/removeobjects(forkeys:).md)
