Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic UseCases and UseCaseProvider #62

Open
hackolein opened this issue Mar 20, 2019 · 0 comments
Open

Generic UseCases and UseCaseProvider #62

hackolein opened this issue Mar 20, 2019 · 0 comments

Comments

@hackolein
Copy link

Hello,

is it possible to make the Post Type in the PostUseCase as associatedtype so I write the required method only once:
I started to write the Code, but It dont't work.

Here is the General UseCase in Domain:

public protocol UseCase {
    associatedtype E
    func many() -> Observable<[E]>
    func save(entry: E) -> Observable<Void>
    func delete(entry: E) -> Observable<Void>
}

Here is the General UseCaseProvider in Domain:

public protocol UseCaseProvider {        
    associatedtype U: UseCase
    func makeUseCase() -> U
}

Here is the UserCaseProvider in CoreDataPlatform:

public final class PostUseCaseProvider: Domain.UseCaseProvider {
     private let coreDataStack = CoreDataStack()
    private let postRepository: Repository<Post>

    public init() {
        postRepository = Repository<Post>(context: coreDataStack.context)
    }

    public func makeUseCase() -> Domain.UseCase {
        return PostsUseCase(repository: postRepository)
    }
}

Here get the error Type 'UserCaseProvider' does not conform to protocol 'UseCaseProvider' and Protocol 'UseCase' can only be used as a generic constraint because it has Self or associated type requirements'

Any idea?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant