> On Jan 8, 2018, at 11:02 AM, Marc Palmer via swift-users > <swift-users@swift.org> wrote: > > Hi, > > It’s hard to be 100% certain because of bugs.swift.org being down currently, > but I believe I have hit this bug:
Just an FYI, I think it is back up now (it is for me). Did you just try? +CC swift-infrastructure. > > https://bugs.swift.org/browse/SR-6039 "A `protocol A: class` is not any > `AnyObject`” > > This is marked as a duplicate of a presumably very old issue judging by its > low number: > > https://bugs.swift.org/browse/SR-55 "non-@objc protocol existentials do not > conform to their own protocol type" > > So, I have a protocol: > > public protocol ActionAuditorObserver: AnyObject { > func actionAuditorInserted(entries: [ActionAuditEntry]) > } > > …where ActionAuditEntry is a struct. > > Trying to use a generic collection of my own for these, of the form: > > class ObserverSet<T: AnyObject> { > … > } > > Using: > > let observers = ObserverSet<ActionAuditorObserver>() > > …results in "'ActionAuditorObserver' is not convertible to ‘AnyObject’”. > > I think this is indeed SR-6039, which makes me really sad as it implies this > is not going to be fixed imminently. > > I am trying to write this as a pure-swift framework as so far have succeeded. > If I add @objc to the protocol as a workaround for this, I then can no longer > have the observer pass in an array of structs. > > So then I have to change the struct to a class, and I’m pushed farther away > from my goals :( > > Is there anything I am missing, or a better way to workaround this? > > I have to have the ObserverSet require AnyObject because it needs to do > identity checking when removing them. Equatable does not make sense for > observers. Losing the struct and forcing @objc feels like such a bitter pill > for something so simple. > > Thanks in advance > Marc > > _______________________________________________ > swift-users mailing list > swift-users@swift.org > https://lists.swift.org/mailman/listinfo/swift-users _______________________________________________ swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users