Open crashoverride777 opened 6 years ago
More Swifty router implemented in PR #25. Instead of segues
, use the extended show
API with completion handler for configuring target view controller:
class ListOrdersRouter: NSObject, RouterProtocol,...
{
func routeToShowOrder(for id: String)
{
show(storyboard: .showOrder) { (destinationVC: ShowOrderViewController) in
let selectedOrder = self.dataStore?.orders?.first { $0.id == id }
var destinationDS = destinationVC.router!.dataStore!
self.passDataToShowOrder(for: selectedOrder, destination: &destinationDS)
}
}
func routeToCreateOrder()
{
show(storyboard: .createOrder) { (destinationVC: CreateOrderViewController) in
var destinationDS = destinationVC.router!.dataStore!
self.passDataToCreateOrder(source: self.dataStore!, destination: &destinationDS)
}
}
Also, each scene has its own storyboard instead of placed all in one main storyboard:
Let me know what you think.
Hey, the changes are very nice. Separate storyboards for each unique scene is the way to go. However the router class itself is still not swifty. Swift is a protocol and extension orientated language, so having a class with 2 methods and a weak property to the VC is clunky. It’s also a memory leaker if weak is forgot as the VC is also referencing the rooter class. That whole class for example could easily just be a extension of the view controller, optionally in a new swift file. I am just pointing this out as I feel clean architecture is outdated for Swift, especially they way most tutorials and the cleanSwift website do it. Thanks for your detailed reply and your awesome repo.
Cool thx for taking a look and the feedback. I definitely agree with all your points.
I have another repo called stateless_arch
where all parts are value-type structs instead of classes. My thought is the architectural flow should be stateless and immutable, with the exception of the view controller of course. That should be safer, simpler to think about, and in the spirit of Swift philosophy. It’s a bit of work so still chipping away at it.
A lot of this architecture seems very unswifty and seems designed for older languages. For example no good swift developer would use the clunky Router class instead of a simple extension of the view controller.