title: ForEach over an array of protocol implementations?
body: <p>I'm starting to learn SwiftUI, and so I decided to write a simple password manager as a learning exercise.  I've defined a <code>protocol</code> with the common attributes in my passwords:</p>
  <pre><code>protocol Secret: Codable {
      
      var id: String { get set }
      var name: String { get set }
      var createdDate: Date { get set }
      
      var favorite: Bool { get set }
      
      var category: SecretCategory { get set }
      
      var notes: String { get set }
      
      init(_ id: String, name: String)
      init(_ id: String, name: String, favorite: Bool)
  
  }
  </code></pre>
  <p>Then, I've defined a couple of Swift <code>struct</code>s that implement this <code>protocol</code> and define the properties of various types of secrets:</p>
  <pre><code>struct LoginSecret: Secret, Identifiable {
      
      var id: String
      var name: String
      var createdDate: Date = Date()
      
      var favorite: Bool = false
      
      var category: SecretCategory = .login
      
      var notes: String = &quot;&quot;
      
      var username: String = &quot;&quot;
      var encryptedPassword: String = &quot;&quot;
      
      var websiteURLs: [String] = []
      
      init(_ id: String, name: String) {
          self.id = id
          self.name = name
      }
      
      init(_ id: String, name: String, favorite: Bool) {
          self.id = id
          self.name = name
          self.favorite = favorite
      }
  }
  </code></pre>
  <p>...and...</p>
  <pre><code>struct BankAccountSecret: Secret, Identifiable {
      
      var id: String
      var name: String
      var createdDate: Date = Date()
      
      var favorite: Bool = false
      
      var category: SecretCategory = .bankAccounts
      
      var notes: String = &quot;&quot;
      
      var bankName: String = &quot;&quot;
      var nameOnAccount: String = &quot;&quot;
      var routingNumber: String = &quot;&quot;
      var accountNumber: String = &quot;&quot;
      
      var swift: String = &quot;&quot;
      var iban: String = &quot;&quot;
      
      var encryptedPIN: String = &quot;&quot;
      
      var branchPhoneNumber: String = &quot;&quot;
      var branchAddress: Address = Address()
      
      init(_ id: String, name: String) {
          self.id = id
          self.name = name
      }
      
      init(_ id: String, name: String, favorite: Bool) {
          self.id = id
          self.name = name
          self.favorite = favorite
      }
  }
  </code></pre>
  <p>These work just fine, and I'm able to Encode/Decode values in JSON for display later.  However, now I'm working on my SwiftUI code.  I want to display each item in a <code>List</code>, iterating over an <code>Array</code> of <code>Secret</code> objects using SwiftUI's <code>ForEach</code>.  My code looks like this:</p>
  <pre><code>struct SecretsListView: View {
  
      @State    
      var secrets: [Secret]
      
      var body: some View {
          NavigationView {
              List {
                 ForEach(secrets) { secret in
                    &lt;snip&gt;
                 }
              }
          }
     }
  }
  </code></pre>
  <p>However, when I compile I get an error saying...</p>
  <pre><code>Value of protocol type 'Secret' cannot conform to 'Identifiable'; only struct/enum/class types can conform to protocols
  </code></pre>
  <p>Is there no way to iterate over an array of <code>Secret</code> objects?  Is there a different way to accomplish this?  Is this issue specific to SwiftUI's <code>ForEach</code>?  Should I use the standard Swift <code>Array</code> <code>forEach</code> method instead?  Any guidance you can provide is greatly appreciated.  I've worked with Swift and UIKit for a while, but SwiftUI is new and I want to make sure I'm developing for the framework correctly.</p>