<!--
{
  "availability" : [
    "iOS: 4.0.0 -",
    "iPadOS: 4.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.6.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSCacheDelegate/cache(_:willEvictObject:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(pl)NSCacheDelegate(im)cache:willEvictObject:"
  },
  "title" : "cache(_:willEvictObject:)"
}
-->

# cache(_:willEvictObject:)

Called when an object is about to be evicted or removed from the cache.

```
optional func cache(_ cache: NSCache<AnyObject, AnyObject>, willEvictObject obj: Any)
```

## Parameters

`cache`

The cache with which the object of interest is associated.

`obj`

The object of interest in the cache.

## Discussion

It is not possible to modify `cache` from within the implementation of this delegate method.

---

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)