Static member cannot be used on protocol metatype

Hi all,

I'm trying to put a static method on a protocol and I'm wondering why this isn't possible:

protocol Proto { }

extension Proto {
	static func action() {
		print("Here!")
	}
}

Proto.action()/*
^~~~~ ~~~~~~
error: static member 'action' cannot be used on protocol metatype 'Proto.Protocol'*/

Protocol extensions add members to concrete types which conform to the protocol. There is currently no way to add members to the protocol type itself.

A recent thread of Swift Evolution proposed to add this functionality, but it is still in the pre-pitch phase.

4 Likes

Use class keyword instead.