johnpatrickmorgan/TCACoordinators

How can we routes to check existing views?

lmw4051 opened this issue ยท 6 comments

Can we use "var routes: [Route]" to check existing views we pushed to the stack before? If so, is there any example code I can follow with?

Hi @lmw4051! Yes the routes array can be inspected at runtime. For example, a lot of the utility methods exposed on arrays of routes inspect the current state of the array.

Hi @lmw4051! Yes the routes array can be inspected at runtime. For example, a lot of the utility methods exposed on arrays of routes inspect the current state of the array.

Thanks for the reply, but at the moment I still don't know how to check the existing views inside the routes. Can you give me an example? Thanks in advance.

I'm a bit unsure what you want to achieve but you can iterate through the routes and access each route's screen (e.g. MyScreen in a [Route<MyScreen>]:

for route in routes {
  print(route.screen)
}

Or inspect the final screen:

print(routes.last?.screen)

I'm a bit unsure what you want to achieve but you can iterate through the routes and access each route's screen (e.g. MyScreen in a [Route<MyScreen>]:

for route in routes {
  print(route.screen)
}

Or inspect the final screen:

print(routes.last?.screen)

I'm a bit unsure what you want to achieve but you can iterate through the routes and access each route's screen (e.g. MyScreen in a [Route<MyScreen>]:

for route in routes {
  print(route.screen)
}

Or inspect the final screen:

print(routes.last?.screen)

Thanks for the reply. What I want to achieve is to check the existing views which has been pushed before, like in UIKit, we can use navigationController.viewControllers to inspect the viewControllers in the stack or not.

So, we can use screen comparison to achieve the function mentioned above?

Such as if route.screen == ??

Yes, you can check what views have been pushed before, e.g.:

if let lastScreen = routes.last?.screen {
  switch screen {
  case .home:
    print("Current screen is home")
  case .profile(let username):
    print("Current screen is \(username)'s profile")
  }
}

Yes, you can check what views have been pushed before, e.g.:

if let lastScreen = routes.last?.screen {
  switch screen {
  case .home:
    print("Current screen is home")
  case .profile(let username):
    print("Current screen is \(username)'s profile")
  }
}

Thanks for the reply.