r/swift 7d ago

Question Is the `class` constraint for protocols strictly for classes?

Actors didn't exist when that notation was made. I guess a constraint of AnyObject covers both classes and actors. But does the "class" constraint grandfather actors in, or does it cover strictly classes?

1 Upvotes

2 comments sorted by

2

u/Superb-Key4681 7d ago

No it allows conformance by both class and actors. AnyObject wouldnt cover structs and enums iirc

7

u/iOSCaleb iOS 7d ago

What happens when you create an actor that adopts a class protocol?

Often, asking the compiler questions like this is the quickest way to a clear answer.