Ok, I have made this protocol to cover object caching with the help of Realm. In protocol I define cache: Object?
which type is defined by Realm library.
protocol PersistantCaching {
var cache: Object? { get set }
}
Then I use this protocol in class ClientDetails
it works.
class Client: PersistantCaching {
var cache: Object?
}
But Object
is too general. So in my case I create Object
subclass
class LocalClient: Object {
dynamic var name = ""
}
And now if I change class Client
to support LocalClient
like this
class Client: PersistantCaching {
var cache: LocalClient?
}
I get an error, that Type 'Client' does not conform to protocol 'PersistantCaching'
How to write generic protocol that define a variable which also accepts subclass of specified Type?