title: KMM - Casting a sealed class/interface in swift not possible
body: <p>Within my KMM library I use sealed interfaces/classes to represent certain states/errors.
  I decided to use sealed interfaces/classes because these states must have different associated objects.</p>
  <p>In the Android code, this also works as expected without any problems.</p>
  <p>But in the iOS part, I'm not able to detect the specific state because the cast is not possible.</p>
  <p>The error is independent of whether it is a sealed interface or a sealed class, here as an example:</p>
  <pre><code>sealed class SyncState() {
      object Loading : SyncState()
      data class Active(val syncNumber: String) : SyncState()
      data class Error(val throwable: Throwable) : SyncState()
  }
  </code></pre>
  <p>In the repository within the KMM library, a corresponding SyncState is now returned depending on the state.</p>
  <pre><code>fun currentSyncState(): SyncState {
      if … {
          return SyncState.Error(Throwable(&quot;…&quot;))
      } else if … {
          return SyncState.Active(&quot;…&quot;)
      } else {
          return SyncState.Loading
      }
  }
  </code></pre>
  <p>In iOS, I can also call up this function without any problems.
  The only problem is that I can't tell which state it is from the object that is returned, because the casting doesn't work at any point.</p>
  <pre><code>let state = repo.currentSyncState()
  …
  
  (lldb) po state
  SyncState.Loading@2fe538
  
  (lldb) po state is SyncState
  true
  
  (lldb) po state is SyncState.Loading
  false
  
  (lldb) po type(of: state)
  SyncStateLoading
  
  (lldb) po state as? SyncState.Loading
  nil
  </code></pre>
  <pre><code>let state = repo.currentSyncState()
  …
  
  (lldb) po state
  Active(syncNumber=syncNumber 123)
  
  (lldb) po state is SyncState
  true
  
  (lldb) po state is SyncState.Active
  false
  
  (lldb) po type(of: state)
  SyncStateActive
  
  (lldb) po state as? SyncState.Active
  nil
  </code></pre>
  <p>A possible solution might be to add an additional Type enum case in KMM for every State, but this still does not allow me to process the associated value of the corresponding state.</p>
  <p>Has anyone had similar problems &amp; found a possible solution for them?
  I am grateful for every little advice.</p>
  <p>I'm using Kotlin 1.6.10 and Xcode 13.2 with Swift 5.5.2.</p>