Skip to content

Commit a642bd3

Browse files
committed
Add StoryboardSegue
1 parent 346329f commit a642bd3

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

Library/Core/StoryboardSegueIdentifierProtocol.swift

+26
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ public struct StoryboardSegueIdentifier<Segue, Source, Destination>: StoryboardS
4242
public init(identifier: String) {
4343
self.identifier = identifier
4444
}
45+
46+
/// Create a new StoryboardSegue based on the identifier and source view controller
47+
public func storyboardSegueWithSource(sourceViewController: Source)
48+
-> StoryboardSegue<Segue, Source, Destination>
49+
{
50+
return StoryboardSegue(identifier: self, sourceViewController: sourceViewController)
51+
}
4552
}
4653

4754
/// Typed segue information
@@ -67,3 +74,22 @@ public struct TypedStoryboardSegueInfo<Segue, Source, Destination>: StoryboardSe
6774
/// Segue source view controller
6875
public let sourceViewController: Source
6976
}
77+
78+
/// Segue with identifier and source view controller
79+
public struct StoryboardSegue<Segue, Source, Destination> {
80+
/// Identifier of this segue
81+
public let identifier: StoryboardSegueIdentifier<Segue, Source, Destination>
82+
83+
/// Segue source view controller
84+
public let sourceViewController: Source
85+
86+
/**
87+
Create a new segue based on the identifier and source view controller
88+
89+
- returns: A new StoryboardSegue
90+
*/
91+
public init(identifier: StoryboardSegueIdentifier<Segue, Source, Destination>, sourceViewController: Source) {
92+
self.identifier = identifier
93+
self.sourceViewController = sourceViewController
94+
}
95+
}

Library/UIKit/UIViewController+StoryboardSegueIdentifierProtocol.swift

+8-1
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,16 @@ public extension UIViewController {
1616
- parameter identifier: The R.segue.* that identifies the triggered segue.
1717
- parameter segue: The object that you want to use to initiate the segue. This object is made available for informational purposes during the actual segue.
1818

19-
- SeeAlso: Library for typed block based segues: https://github.com/tomlokhorst/SegueManager
19+
- SeeAlso: Library for typed block based segues: [tomlokhorst/SegueManager](https://github.com/tomlokhorst/SegueManager)
2020
*/
2121
public func performSegueWithIdentifier<Identifier: StoryboardSegueIdentifierType>(identifier: Identifier, sender: AnyObject?) {
2222
performSegueWithIdentifier(identifier.identifier, sender: sender)
2323
}
2424
}
25+
26+
public extension StoryboardSegue where Source : UIViewController {
27+
/// Performs the specified segue
28+
public func performSegue(sender: AnyObject? = nil) {
29+
sourceViewController.performSegueWithIdentifier(identifier.identifier, sender: sender)
30+
}
31+
}

0 commit comments

Comments
 (0)