title: Swift generic types in protocol issue. Protocol can only be used as a generic constraint
body: <p>I have created a protocol for my services:</p>
  
  <pre><code>protocol SaveCoreDataObjectServiceProtocol  {
      associatedtype T
  
      func getPending() -&gt; T?
      func deletePending(with completion: @escaping (ResultInfo&lt;Bool&gt;) -&gt; Void)
  }
  </code></pre>
  
  <p>I have a base class that will be a parent class of any child services:</p>
  
  <pre><code>class BaseSaveCoreDataObjectService&lt;T: DynamicObject&gt;: SaveCoreDataObjectServiceProtocol {
  
      func getPending() -&gt; T? {
  
          let managedObject = try? CoreStore.fetchOne(
              From&lt;T&gt;()
                  .where(
                      format: "%K == %@",
                      #keyPath(BaseMO.pendingToSave),
                      NSNumber(value: true))
          )
  
          return managedObject
      }
  
      func deletePending(with completion: @escaping (ResultInfo&lt;Bool&gt;) -&gt; Void) {
  
          let managedObject = try? CoreStore.fetchOne(
              From&lt;T&gt;()
                  .where(
                      format: "%K == %@",
                      #keyPath(BaseMO.pendingToSave),
                      NSNumber(value: true))
          )
  
          if let unwrappedManagedObject = managedObject {
              CoreStore.perform(
                  asynchronous: { (transaction) -&gt; Void in
                      transaction.delete(unwrappedManagedObject)
                      print("Deleted pending object id: ", (unwrappedManagedObject as? BaseMO)?.id ?? "Deleting pending object with no id issue.")
              },
                  completion: { _ in
                      completion(ResultInfo.data(true))
              }
              )
          }
      } }
  </code></pre>
  
  <p>I have few service which just empty and inherited from <code>BaseSaveCoreDataObjectService</code></p>
  
  <pre><code>class SaveWorkoutService : BaseSaveCoreDataObjectService&lt;WorkoutEntity&gt; {
  
  }
  
  class SaveExerciseService: BaseSaveCoreDataObjectService&lt;ExerciseEntity&gt; {
  
  }
  </code></pre>
  
  <p>When I try to iterate them I get an error <code>Protocol type 'DynamicObject' cannot conform to 'DynamicObject' because only concrete types can conform to protocols</code> here:</p>
  
  <pre><code>func removeAllPendingCoreDataObjectsToSave() {
          let saveObjectServices = [SaveExerciseService(), SaveWorkoutService()] as [BaseSaveCoreDataObjectService&lt;DynamicObject&gt;]
  
          for saveObjectService in saveObjectServices {
              saveObjectService.deletePending { (result) in
  
              }
          }
      }
  </code></pre>
  
  <p>The idea is just to have basic parent service which includes some reusable function like <code>getPending()</code> <code>deletePending()</code> and etc and can return generic type.</p>
  
  <p>If I change this</p>
  
  <pre><code>let saveObjectServices = [SaveExerciseService(), SaveWorkoutService()] as [BaseSaveCoreDataObjectService&lt;DynamicObject&gt;]
  </code></pre>
  
  <p>to this:</p>
  
  <pre><code>let saveObjectServices = [SaveExerciseService(), SaveWorkoutService()] as [SaveCoreDataObjectServiceProtocol]
  </code></pre>
  
  <p>I get this error:</p>
  
  <pre><code>Protocol 'SaveCoreDataObjectServiceProtocol' can only be used as a generic constraint because it has Self or associated type requirements
  </code></pre>