title: Swift protocol with associatedtype as a parameter type
body: <p>So here I have this protocol</p>
  
  <pre><code>public protocol UseCase {
  
      associatedtype ResponseType
      associatedtype Parameters
  
      func build(params: Parameters) -&gt; Single&lt;ResponseType&gt;
  
  }
  
  public extension UseCase {
  
      func execute(params: Parameters) -&gt; Single&lt;ResponseType&gt; {
          return build(params: params)
                  .subscribeOn(ConcurrentDispatchQueueScheduler(qos: DispatchQoS.background))
                  .observeOn(MainScheduler.instance)
      }
  
  }
  </code></pre>
  
  <p>And I have a Struct that implement the <code>UseCase</code> protocol like this</p>
  
  <pre><code>public struct CreateNewAccount: UseCase {
  
      private let repository: AuthRepository
  
      public init(repository: AuthRepository) {
          self.repository = repository
      }
  
      public func build(params: Params) -&gt; Single&lt;User&gt; {
          return repository.register(params: params)
      }
  
      public struct Params: RequestParams {
          ...
      }
  }
  </code></pre>
  
  <p>And I want to use this <code>CreateNewAccount</code> on another class, but I don't want to directly use <code>CreateNewAccount</code> and I want to pass it as a <code>UseCase</code> instead, because since It's a protocol It can be easily mocked for testing.
  But when I do something like this</p>
  
  <pre><code>class RegisterViewModel: ViewModel {
  
      private let createNewAccount: UseCase // Error on this line
  
      init(createNewAccount: UseCase) { // Error on this line
          self.createNewAccount = createNewAccount
      }
  }
  </code></pre>
  
  <p>That gave me an error like this</p>
  
  <pre><code>Error:(34, 35) protocol 'UseCase' can only be used as a generic constraint because it has Self or associated type requirements
  </code></pre>
  
  <p>So, is there's something that I can change from my code to make this kind of case works? Thanks in advance.</p>