JamesSedlacek / Routing

SwiftUI library for abstracting navigation logic from views
MIT License
353 stars 19 forks source link

Following the ReadMe for defining a Routable enum displays errors in Xcode 15.2 #30

Closed michaelaflores closed 9 months ago

michaelaflores commented 9 months ago

When adding the ExampleRoute enum, Xcode displays the following errors:

  1. Non-class type 'ExampleRoute' cannot conform to class protocol 'ObservableObject'
  2. Non-class type 'ExampleRoute' cannot conform to class protocol 'Routable'
  3. Branches have mismatching types 'DetailView' and 'ChatView'

Code, replacing the views with simple views:

import Routing
import SwiftUI

enum DefaultRoute: Routable {
    case detail
    case chat

    var body: some View {
        switch self {
        case .detail:
            DetailView()
        case .chat:
            ChatView()
        }
    }
}

struct ChatView: View {
    var body: some View {
        Text("Chat View")
    }
}

struct DetailView: View {
    var body: some View {
        Text("Default View – Style this with nice background and/or a prompt to Action")
    }
}
JamesSedlacek commented 9 months ago

Try updating to the latest version of the package

michaelaflores commented 9 months ago

Confirmed user error: when adding the dependency I added the release version instead of tracking main (possibly a mis-step from being used to web dependencies). Updating to main fixed it. Thanks @JamesSedlacek 👍🏼