# \#anyhashable

**URL:** https://forums.swift.org/tag/anyhashable/877.md

[Latest](https://forums.swift.org/latest.md) · [Categories](https://forums.swift.org/categories.md) · [Tags](https://forums.swift.org/tags.md)

---

## [Why does casting AnyHashable to NSObject always succeed?](https://forums.swift.org/t/why-does-casting-anyhashable-to-nsobject-always-succeed/82517)

<div class="topic-metadata">

**Author:** [@a7medev](https://forums.swift.org/u/a7medev)\
**Replies:** 2\
**Last updated:** [October 5, 2025, 10:30pm UTC](https://forums.swift.org/t/why-does-casting-anyhashable-to-nsobject-always-succeed/82517 "2025-10-05T22:30:30Z")

</div>

While experimenting with AnyHashable, I was surprised that the following code actually works. import Foundation struct S: Hashable { var a: Int } let hashable = AnyHashable(S(a: 5)) let object: NSObject = hashable…

---

## [Custom AnyXYZ with implicit casting (like AnyHashable)](https://forums.swift.org/t/custom-anyxyz-with-implicit-casting-like-anyhashable/74635)

<div class="topic-metadata">

**Author:** [@pnewell](https://forums.swift.org/u/pnewell)\
**Replies:** 8\
**Last updated:** [September 16, 2024, 9:19pm UTC](https://forums.swift.org/t/custom-anyxyz-with-implicit-casting-like-anyhashable/74635 "2024-09-16T21:19:29Z")

</div>

Has anyone explored implementing a custom AnyXYZ wrapper that works like AnyHashable? For example, if I want to have a AnyHashableCodable wrapper that has similar syntactical sugar so I could do the following: var dict…

---

## [\[0\] as \[AnyHashable\] as? \[Bool\]](https://forums.swift.org/t/0-as-anyhashable-as-bool/66880)

<div class="topic-metadata">

**Author:** [@fumoboy007](https://forums.swift.org/u/fumoboy007)\
**Replies:** 4\
**Last updated:** [August 22, 2023, 9:55pm UTC](https://forums.swift.org/t/0-as-anyhashable-as-bool/66880 "2023-08-22T21:55:45Z")

</div>

I’m noticing some strange behavior with the following code: \[0\] as \[AnyHashable\] as? \[Bool\] swift repl prints nil whereas Xcode prints \[false\]! Two questions: How is swift repl (5.8.1) producing a different result f…
