Skip to content

Instantly share code, notes, and snippets.

@srdanrasic
Last active February 10, 2018 20:46
Show Gist options
  • Save srdanrasic/c0077cc445d4d1179e71e804d04722c6 to your computer and use it in GitHub Desktop.
Save srdanrasic/c0077cc445d4d1179e71e804d04722c6 to your computer and use it in GitHub Desktop.
extension ProfileViewController {
static func makeViewController(_ userService: UserService) -> ProfileViewController {
let viewController = ProfileViewController()
...
viewController.friendsView.reactive.selectedItem
.with(latestFrom: userService.friends, combine: itemAtIndex) // Take element at selected index from friends array
.bind(to: viewController) { viewController, friend in
let userService = userService.makeUserService(for: friend)
viewController.presentFriendViewController(userService)
}
...
}
private func presentFriendViewController(_ userService: UserService) {
let viewController = ProfileViewController.makeViewController(userService)
present(viewController, animated: true)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment