The following is a workaround for the "problem" that protocols and their extensions in Swift do not store properties. It seems to "work" but I am wondering what reasons people might have for avoiding it?
fileprivate var strings: [String] = []
protocol SomeProat {
func add(someString: String)
}
extension SomeProat {
func add(someString: String) {
strings.append(someString)
print(strings)
}
}
(I realise this question could be interpreted as subjective btw).
There is no good way to do what you're asking in pure Swift on non-Apple platforms.
If you are on an Apple platform (macOS, iOS, tvOS, watchOS), and your conforming type is a class, then you can use the associated object support provided by the Objective-C runtime: