https://github.com/geektree0101/cleanroute
CleanSwift, Convenience routing example between scenes
https://github.com/geektree0101/cleanroute
clean-architecture ios swift
Last synced: 15 days ago
JSON representation
CleanSwift, Convenience routing example between scenes
- Host: GitHub
- URL: https://github.com/geektree0101/cleanroute
- Owner: GeekTree0101
- Created: 2019-09-21T06:54:07.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-09-28T12:08:41.000Z (over 6 years ago)
- Last Synced: 2025-11-14T21:28:41.372Z (7 months ago)
- Topics: clean-architecture, ios, swift
- Language: Swift
- Size: 70.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# CleanRouter
> CleanSwift, Convenience routing example between scenes [Research Repository]
[](https://geektree0101.github.io/)

### Hard codeded finding previous viewController logic
> EditRouter.swift
```swift
func movingFromParent(segue: UIStoryboardSegue?) {
if let segue = segue {
let destinationVC = segue.destination as? ShowViewController
destinationVC?.router?.dataStore?.content = self.dataStore?.content
} else {
let destinationVC = self.viewController?.navigationController?.topViewController as? ShowViewController
destinationVC?.router?.dataStore?.content = self.dataStore?.content
}
}
func dismiss(segue: UIStoryboardSegue?) {
if let segue = segue {
let destinationVC = segue.destination as? ShowViewController
destinationVC?.router?.dataStore?.content = self.dataStore?.content
} else {
let parentNavVC = self.viewController?.navigationController?.presentingViewController as? UINavigationController
let destinationVC = parentNavVC?.topViewController as? ShowViewController
destinationVC?.router?.dataStore?.content = self.dataStore?.content
self.viewController?.dismiss(animated: true)
}
}
```
In Storyboard case, doesn't matter about finding previous viewController.
but, Hard codeded find previous viewController logic isn't only hard to define previous viewController also easy to occur unexpected bugs.
### Using defined sourceVC prop from DataPassing
In my case, EditorDataPassing supports defined previous viewController property. aka sourceVC(UIViewController)
> EditorRouter.swift
```swift
protocol EditorDataPassing: class {
var dataStore: EditorDataStore? { get }
var sourceVC: UIViewController? { get set } // <- Here!!!!!
}
```
> ShowRouter.swift
```swift
extension ShowRouter: ShowRouterLogic {
func presentEditor() {
let editorVC = EditorViewController.init()
editorVC.router?.dataStore?.content = dataStore?.content
editorVC.router?.sourceVC = vc // <- Here!!!!!
let navVC = UINavigationController(rootViewController: editorVC)
vc?.present(navVC, animated: true, completion: nil)
}
func pushEditor() {
let editorVC = EditorViewController.init()
editorVC.router?.dataStore?.content = dataStore?.content
editorVC.router?.sourceVC = vc // <- Here!!!!!
vc?.navigationController?.pushViewController(editorVC, animated: true)
}
}
```
> EditorRouter.swift
```swift
func movingFromParent(segue: UIStoryboardSegue?) {
if let segue = segue {
let destinationVC = segue.destination as? ShowViewController
destinationVC?.router?.dataStore?.content = self.dataStore?.content
} else {
let destinationVC = self.sourceVC as? ShowViewController
destinationVC?.router?.dataStore?.content = self.dataStore?.content
}
}
func dismiss(segue: UIStoryboardSegue?) {
if let segue = segue {
let destinationVC = segue.destination as? ShowViewController
destinationVC?.router?.dataStore?.content = self.dataStore?.content
} else {
let destinationVC = self.sourceVC as? ShowViewController
destinationVC?.router?.dataStore?.content = self.dataStore?.content
self.viewController?.dismiss(animated: true)
}
}
```