Skip to content
This repository was archived by the owner on Sep 19, 2024. It is now read-only.

Add StoryboardSegue #2

Merged
merged 2 commits into from
Feb 6, 2016
Merged

Add StoryboardSegue #2

merged 2 commits into from
Feb 6, 2016

Conversation

tomlokhorst
Copy link
Collaborator

Starting work on mac-cain13/R.swift#158

With this, a segue (identifier & source) can be wrapped up in a new value, e.g.:

let segueFromSecondToThird = R.segue.secondViewController.toThird.storyboardSegueWithSource(self)

And it can later on be performed:

segueFromSecondToThird.performSegue()

@tomlokhorst
Copy link
Collaborator Author

I've removed the UIViewController extension performSegueWithIdentifier and replaced it with one that only works on segues with the correct source view controller type.

For example:

// This wil compile
let master = MasterViewController()
master.performSegueWithIdentifier(R.segue.masterViewController.goToDetail)

// This won't compile, because the `Source` types don't match
let detail = DetailViewController()
detail.performSegueWithIdentifier(R.segue.masterViewController.goToDetail)

@@ -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.

@mac-cain13 mac-cain13 merged commit d4c4bda into mac-cain13:master Feb 6, 2016
@mac-cain13
Copy link
Owner

Merged. I renamed the protocol to SeguePerformerType

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants