<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/UserDefaults/removeObject(forKey:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSUserDefaults(im)removeObjectForKey:"
  },
  "title" : "removeObject(forKey:)"
}
-->

# removeObject(forKey:)

Removes the value for the specified key from the defaults database.

```
func removeObject(forKey defaultName: String)
```

## Parameters

`defaultName`

The key with the value you want to remove.

## Discussion

This method removes the specified key and value from the app-specific settings.
If your `UserDefaults` object writes to settings for an app group or other shared
settings file, the method removes the key from that file instead. This method
removes the key and value only from the target domain, and doesn’t impact values
for the same key in other domains. For example, it doesn’t remove keys and values
from the global domain.

After you remove the key, the system generates a [`didChangeNotification`](/documentation/Foundation/UserDefaults/didChangeNotification)
for registered observers.

---

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)