class UserProfileViewController: UIViewController, DataReceivingViewController {
typealias DataType = User
func didReceiveData(_ data: User) {
// configure UI with data
}
}
struct UserProfile: Route, RoutePatternsAware {
typealias Destination = UserProfileViewController
let userId: String
var parameters: [String : Any]? {
return [
"userId":self.userId
]
}
/*-------- routing part --------*/
static var patterns: [String] = [
"https://myapp.com/user/:userId(.*)"
]
static func route(handler: RouteHandler<UserProfile>) {
let userId = handler.parameters?["userId"] as? String
// e.g. fetch user from network
fetchUser(userId, completion: { (user: User) in
// notify handler
handler.complete(data: user)
})
}
}
present { $0
// configure navigation
.to(UserProfile(userId: "123456")
.animated(false)
...
}
or
UserProfile(userId: "123456").present { $0
// configure navigation
.animated(false)
...
}
or
UserProfile(userId: "123456").present()
present { $0
// configure navigation
.to("https://myapp.com/user/123456")
.animated(false)
...
}
or
"https://myapp.com/user/123456".present { $0
// configure navigation
.animated(false)
...
}
or
"https://myapp.com/user/123456".present()
UserProfile(userId: "123456").viewController { (viewController: UserProfileViewController) in
...
}
"https://myapp.com/user/123456".viewController { (viewController: UIViewController) in
...
}
Moze li se presentanje routea obavit ovako (animated je izvan closurea):
?