I wanted to develop an application which uses repository patterns using core data and realm. I want to resolve protocol according to my needs. Purpose is to inject a generic core data repository / realm repository protocol in the assembly.
Problem occurs on this line saying Protocol 'SleepRepositoryProtocol' can only be used as a generic constraint because it has Self or associated type requirements
func assemble(container: Container) {
container.register(SleepRepositoryProtocol.self) { r in
CoreDataSleepRepository(persistentContainer:r.resolve(NSPersistentContainer.self)!)
}.inObjectScope(.container)
}
I am unable to inject sleep repository protocol because of using generic (associated type) properties. How can I solve this problem?
Additionally,thank you very much for your response. It really helped me a lot. I have one more issue with this.
var repository: SleepRepositoryProtocol
var items: [SleepEntity]?
private let assembler: Assembler
init(assembler: Assembler) {
self.assembler = assembler
repository = assembler.resolver.resolve(SleepRepositoryProtocol.self)!
}
This gives me error "Protocol 'SleepRepositoryProtocol' can only be used as a generic constraint because it has Self or associated type requirements" and I don't know how to resolve my SleepRepositoryProtocol.