I’m trying to create public interface for my class operating on generics.
I’ve created interface
<code>public protocol StorageProtocol {
associatedtype StorageObject: Codable
func store(storeObject: StorageObject)
func get() -> StorageObject?
}
</code>
<code>public protocol StorageProtocol {
associatedtype StorageObject: Codable
func store(storeObject: StorageObject)
func get() -> StorageObject?
}
</code>
public protocol StorageProtocol {
associatedtype StorageObject: Codable
func store(storeObject: StorageObject)
func get() -> StorageObject?
}
and implementation
<code>public class Storage<T: Codable>: StorageProtocol {
public func store(storeObject: T) {}
public func get() -> T?
</code>
<code>public class Storage<T: Codable>: StorageProtocol {
public func store(storeObject: T) {}
public func get() -> T?
</code>
public class Storage<T: Codable>: StorageProtocol {
public func store(storeObject: T) {}
public func get() -> T?
Now, when I try to create instance it forces me any keyword
<code>let myStorage: any StorageProtocol = Storage<Credentials>()
</code>
<code>let myStorage: any StorageProtocol = Storage<Credentials>()
</code>
let myStorage: any StorageProtocol = Storage<Credentials>()
and I can’t call storage.store(storeObject: Credentials())
as I’m getting error:
Associated type ‘StorageObject’ can only be used with a concrete type or generic parameter base.
What I’m missing here?