"class" as a thing that can be inherited

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?

It's another name for 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.

2 Likes

Ah, thanks.

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

1 Like

It's been deprecated, or something.

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

1 Like

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

AnyObject is fine for me.

2 Likes
Terms of Service

Privacy Policy

Cookie Policy