# "class" as a thing that can be inherited

**URL:** <https://forums.swift.org/t/class-as-a-thing-that-can-be-inherited/43880>\
**Category:** Using Swift\
**Created:** [January 15, 2021, 6:18pm UTC](https://forums.swift.org/t/class-as-a-thing-that-can-be-inherited/43880 "2021-01-15T18:18:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hacksaw](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/hacksaw/32/32775_2.png) [@Hacksaw](https://forums.swift.org/u/Hacksaw)\
**Post date:** [January 15, 2021, 6:18pm UTC](https://forums.swift.org/t/class-as-a-thing-that-can-be-inherited/43880/1 "2021-01-15T18:18:55Z")

</div>

In another thread, I saw this construction:

```
protocol AssetInstance : class {
    var identifier: String { get set }
}

```

Which, to my astonishment, compiles. I can't seem to find documentation for this use of the keyword "class".

Could I get a pointer, please?

---

<div class="post-metadata">

**Author:** ![krilnon](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/krilnon/32/276_2.png) [@krilnon](https://forums.swift.org/u/krilnon)\
**Post date:** [January 15, 2021, 6:22pm UTC](https://forums.swift.org/t/class-as-a-thing-that-can-be-inherited/43880/2 "2021-01-15T18:22:23Z")

</div>

It's another name for [`AnyObject`](https://developer.apple.com/documentation/swift/anyobject).

> This proposal merges the concepts of `class` and `AnyObject` , which now have the same meaning: they represent an existential for classes. To get rid of the duplication, we suggest only keeping `AnyObject` around. To reduce source-breakage to a minimum, `class` could be redefined as `typealias class = AnyObject` and give a deprecation warning on `class` for the first version of Swift this proposal is implemented in. Later, `class` could be removed in a subsequent version of Swift.

> <https://github.com/apple/swift-evolution/blob/main/proposals/0156-subclass-existentials.md#class-and-anyobject>

---

<div class="post-metadata">

**Author:** ![Hacksaw](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/hacksaw/32/32775_2.png) [@Hacksaw](https://forums.swift.org/u/Hacksaw)\
**Post date:** [January 15, 2021, 6:26pm UTC](https://forums.swift.org/t/class-as-a-thing-that-can-be-inherited/43880/3 "2021-01-15T18:26:29Z")

</div>

Ah, thanks.

---

<div class="post-metadata">

**Author:** ![Tino](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/tino/32/1073_2.png) [@Tino](https://forums.swift.org/u/Tino)\
**Post date:** [January 15, 2021, 10:46pm UTC](https://forums.swift.org/t/class-as-a-thing-that-can-be-inherited/43880/4 "2021-01-15T22:46:49Z")

</div>

You are lucky —I tell people all the time to use `AnyObject`; I guess the old spelling will never fade away ☹

---

<div class="post-metadata">

**Author:** ![phoneyDev](https://avatars.discourse-cdn.com/v4/letter/p/49beb7/32.png) [@phoneyDev](https://forums.swift.org/u/phoneyDev)\
**Post date:** [January 15, 2021, 11:20pm UTC](https://forums.swift.org/t/class-as-a-thing-that-can-be-inherited/43880/5 "2021-01-15T23:20:36Z")

</div>

It's been deprecated, or something.

> [@Class-only protocols, class vs AnyObject?](https://forums.swift.org/t/class-only-protocols-class-vs-anyobject/11507):
>
> What is the difference, if any, btw P and Q here: protocol P : class { ... } protocol Q : AnyObject { ... } If no difference, which should be preferred? (I got the impression that the class version was meant to be deprecated, but it still compiles without warnings as of Xcode 9.3)

---

<div class="post-metadata">

**Author:** ![Nevin](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/nevin/32/617_2.png) [@Nevin](https://forums.swift.org/u/Nevin)\
**Post date:** [January 16, 2021, 12:17am UTC](https://forums.swift.org/t/class-as-a-thing-that-can-be-inherited/43880/6 "2021-01-16T00:17:49Z")

</div>

Personally, I think `class` is much clearer in its meaning than `AnyObject`.

---

<div class="post-metadata">

**Author:** ![Hacksaw](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/hacksaw/32/32775_2.png) [@Hacksaw](https://forums.swift.org/u/Hacksaw)\
**Post date:** [January 16, 2021, 12:32am UTC](https://forums.swift.org/t/class-as-a-thing-that-can-be-inherited/43880/7 "2021-01-16T00:32:04Z")

</div>

Not for me. Not in lowercase. It looks like a mistake. If is was Class, mirroring Self, maybe.

AnyObject is fine for me.
