Last active
March 9, 2016 15:32
-
-
Save rizumita/d02427ddbd1d73d6e924 to your computer and use it in GitHub Desktop.
Using UIStoryboardSegue for purposes of injecting dependencies and passing data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BundleSegue: ConfigurationSegue { | |
typealias Source = BundlesViewController | |
typealias Destination = BundleViewController | |
typealias First = BundlesViewController | |
typealias Second = BundleViewController | |
override func inject() { | |
destinationController.viewModel = resolver.resolve(BundleViewModelType.self) | |
} | |
override func propagate() { | |
second.id = first.selectedID | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import Swinject | |
class ConfigurationSegue: UIStoryboardSegue, InjectionSegueType, PropagationSegueType { | |
typealias Source = UIViewController | |
typealias Destination = UIViewController | |
typealias First = UIViewController | |
typealias Second = UIViewController | |
func inject() { | |
} | |
func propagate() { | |
} | |
override func perform() { | |
self.inject() | |
self.propagate() | |
super.perform() | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import Swinject | |
protocol InjectionSegueType { | |
typealias Source: UIViewController | |
typealias Destination: UIViewController | |
var sourceController: Source { get } | |
var destinationController: Destination { get } | |
var resolver: Resolvable { get } | |
func inject() | |
} | |
extension InjectionSegueType where Self: UIStoryboardSegue { | |
var sourceController: Source { | |
return sourceViewController as! Source | |
} | |
var destinationController: Destination { | |
return destinationViewController as! Destination | |
} | |
var resolver: Resolvable { | |
return assembler.resolver | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
protocol PropagationSegueType { | |
typealias First | |
typealias Second | |
var first: First { get } | |
var second: Second { get } | |
func propagate() | |
} | |
extension PropagationSegueType where Self: UIStoryboardSegue { | |
var first: First { | |
return sourceViewController as! First | |
} | |
var second: Second { | |
return destinationViewController as! Second | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment