Skip to content
This repository was archived by the owner on Sep 19, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Library/Core/StoryboardSegueIdentifierProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ public struct StoryboardSegueIdentifier<Segue, Source, Destination>: StoryboardS
public init(identifier: String) {
self.identifier = identifier
}

/// Create a new StoryboardSegue based on the identifier and source view controller
public func storyboardSegueWithSource(sourceViewController: Source)
-> StoryboardSegue<Segue, Source, Destination>
{
return StoryboardSegue(identifier: self, sourceViewController: sourceViewController)
}
}

/// Typed segue information
Expand All @@ -67,3 +74,22 @@ public struct TypedStoryboardSegueInfo<Segue, Source, Destination>: StoryboardSe
/// Segue source view controller
public let sourceViewController: Source
}

/// Segue with identifier and source view controller
public struct StoryboardSegue<Segue, Source, Destination> {
/// Identifier of this segue
public let identifier: StoryboardSegueIdentifier<Segue, Source, Destination>

/// Segue source view controller
public let sourceViewController: Source

/**
Create a new segue based on the identifier and source view controller

- returns: A new StoryboardSegue
*/
public init(identifier: StoryboardSegueIdentifier<Segue, Source, Destination>, sourceViewController: Source) {
self.identifier = identifier
self.sourceViewController = sourceViewController
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,29 @@
import Foundation
import UIKit

public extension UIViewController {
public protocol UIViewControllerType {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really like the name of this protocol and the empty extension below. Could we change it to just an extension of UIViewController?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it can't be an extension on UIViewController, because of the Self requirement:

'Self' is only available in a protocol or as the result of a method in a class; did you mean 'UIViewController'?

So that's why a protocol is needed. I'm unsure if there is some fundamental type system reason for this. Or simply a limitation of the current Swift compiler implementation. If its a "bug" in the compiler, we can assume it will be fixed at some point in the future, and then we can remove this protocol.

And yeah, I don't really like the name either. I thought of it because of things like CollectionType and SequenceType. ¯_(ツ)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point. We should only think about a better name in that case.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatives:

  • PerformSegueWithIdentifierable
  • PerformSegueable
  • Segueable
  • UIViewControllerPerformSegue
  • ViewControllerSegueable

I don't really like any of these, but I'm slightly leaning to the last ViewControllerSegueable.

func performSegueWithIdentifier(identifier: String, sender: AnyObject?)
}

extension UIViewController: UIViewControllerType { }

public extension UIViewControllerType {
/**
Initiates the segue with the specified identifier (R.segue.*) from the current view controller'€™s storyboard file.

Initiates the segue with the specified identifier (R.segue.*) from the current view controller's storyboard file.
- parameter identifier: The R.segue.* that identifies the triggered segue.
- 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.

- SeeAlso: Library for typed block based segues: https://github.com/tomlokhorst/SegueManager
*/
public func performSegueWithIdentifier<Identifier: StoryboardSegueIdentifierType>(identifier: Identifier, sender: AnyObject?) {
- parameter sender: The object that you want to use to initiate the segue. This object is made available for informational purposes during the actual segue.
- SeeAlso: Library for typed block based segues: [tomlokhorst/SegueManager](https://github.com/tomlokhorst/SegueManager)
*/
public func performSegueWithIdentifier<Segue, Destination>(
identifier: StoryboardSegueIdentifier<Segue, Self, Destination>,
sender: AnyObject?) {
performSegueWithIdentifier(identifier.identifier, sender: sender)
}
}

public extension StoryboardSegue where Source : UIViewController {
/// Performs the specified segue
public func performSegue(sender: AnyObject? = nil) {
sourceViewController.performSegueWithIdentifier(identifier.identifier, sender: sender)
}
}