Vyacheslav
Vyacheslav

Reputation: 27211

Obtain a name of a protocol programmatically

How can I retrieve the name of a protocol programmatically?

protocol SomeProtocol {
func printName()
}

extension SomeProtocol {
func printName() {
print("Name?")
}
}

Upvotes: 0

Views: 48

Answers (1)

TheTiger
TheTiger

Reputation: 13354

print(SomeProtocol.self)

Or if you want as String

let name = String(describing: SomeProtocol.self)
print(name)

Upvotes: 1

Related Questions