[swift-evolution] Passing class protocols to functions accepting AnyObject

Christopher Kornher ckornher at me.com
Tue Dec 6 13:53:45 CST 2016

This issue bites me frequently and is a barrier to clean "protocol-based” programming. This is extremely counter-intuitive to me, at least. Not having a good workaround for this really makes the language seem incomplete.

Recently I had the need to use instances of a protocol as keys in a dictionary (yes, there was a very good reason for it). I assume that this was the reason that I could get it to work. I ended-up having the use instances of an abstract class, but of course, the powers that be think that abstract classes should be second-class citizens in Swift. This is off-topic, but not having a good construct for abstract methods was a mistake in Obj-C and it is a mistake in Swift.

- Chris

> On Dec 6, 2016, at 12:30 PM, Андрей Володин via swift-evolution <swift-evolution at swift.org> wrote:
> Been struggling with this kind of problem. My case: I have an array of class protocol and can’t use my extension that removes AnyObject from array by comparing pointers via ===. 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

More information about the swift-evolution mailing list