• Stars
    star
    133
  • Rank 272,600 (Top 6 %)
  • Language
    Swift
  • License
    MIT License
  • Created over 9 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Perform storyboard segues with closures, in Swift

SegueManager


With SegueManager it's easy to programatically perform segues and update the destination view controller. The following example demonstrates how to perform a segue and set a view model:

segueManager.performSegue(withIdentifier: "showDetails") { (details: DetailsViewController) in
  details.viewModel = DetailsViewModel("This is the details view model")
}

See the full iOS example, or read below for usage instructions.

Typed segues with R.swift

A major design goal of SegueManager 2.0 is to allow completely statically typed segues using R.swift.

With R.swift the above example becomes:

self.performSegue(withIdentifier: R.segue.masterViewController.showDetails) { segue in
  segue.destination.viewModel = DetailsViewModel("This is the details view model")
}

Here the segue parameter is of type: TypedStoryboardSegueInfo<UIStoryboardSegue, MasterViewController, DetailViewController>, which means the .destination field is of the correct type.

To use R.swift together with SegueManager, include this subspec to your Podfile:

pod 'SegueManager/R.swift'

Installation

CocoaPods

SegueManager is available for both iOS and OS X. Using CocoaPods, SegueManager can be integrated into your Xcode project by specifying it in your Podfile:

pod 'SegueManager'

Then, run the following command:

$ pod install

Usage

There are two methods of using SegueManager:

  1. Inherit from one of the base types: SegueManagerViewController, SegueManagerTableViewController, SegueManagerCollectionViewController, etc.

  2. Or, if you don't want to rely on inheritance (often problematic), create a SegueManager yourself:

  3. On your ViewController, create a SegueManager, instantiated with self.

  4. Implement the SeguePerformer protocol

  5. Override prepare(for:) and call SegueManager.

import SegueManager

class MasterViewController: UIViewController, SeguePerformer {

  lazy var segueManager: SegueManager = {
    // SegueManager based on the current view controller
    return SegueManager(viewController: self)
  }()

  override func prepare(for segue: UIStoryboardSegue, sender: AnyObject?) {
    segueManager.prepare(for: segue)
  }
}

After this setup, simply call performSegue on self and pass it a handler.

With SegueManager only

Call performSegue(withIdentifier) with a string identifier and pass a handler. Make sure you specify the type of the destination ViewController, since that can not be inferred:

self.performSegue(withIdentifier: "showDetails") { (details: DetailsViewController) in
  details.viewModel = DetailsViewModel("This is the details view model")
}

With SegueManager + R.swift

Call performSegue(withIdentifier) with a segue identifier from R.segue.* and pass a handler.

self.performSegue(withIdentifier: R.segue.masterViewController.showDetails) { segue in
  segue.destination.viewModel = DetailsViewModel("This is the details view model")
}

The handler will be called after the destination view controller has been instantiated, but before its view has been loaded or any animations start.

Releases

  • 5.0.0 - 2021-03-05 - Bump minimum version to iOS 9
  • 4.2.0 - 2019-08-28 - Swift 5.1 support
  • 4.1.0 - 2019-06-10 - Untested Carthage support
  • 4.0.0 - 2018-05-19 - Swift 4.1 support
  • 3.1.0 - 2017-01-05 - Add tvOS support
  • 3.0.0 - 2016-09-13 - Swift 3 support
  • 2.1.0 - 2016-03-22 - Swift 2.2 support
  • 2.0.0 - 2016-02-10 - R.swift improvements
  • 1.3.0 - 2016-01-23 - Add SegueManagerViewController as UIViewController subclass
  • 1.2.0 - 2016-01-15 - Add R.swift support
  • 1.1.0 - 2015-09-22 - Added Carthage support
  • 1.0.0 - 2015-09-11 - Swift 2 support
  • 0.9.1 - 2015-08-13 - Support for nested UINavigationController in destination
  • 0.9.0 - 2015-03-20 - Print warning when forgot to call perpareForSegue
  • 0.5.0 - 2015-03-05 - Initial public release
  • 0.0.0 - 2014-10-12 - Initial private version for project at Q42

Licence & Credits

SegueManager is written by Tom Lokhorst of Q42 and available under the MIT license, so feel free to use it in commercial and non-commercial projects.

More Repositories

1

XcodeEdit

Swift library for reading and writing Xcode project files in OpenStep format
Swift
204
star
2

CloudStorage

Swift
93
star
3

swift-json-gen

Generate Json encoders and decoders based on Swift structs with good error handling
JavaScript
76
star
4

Promissum

A promises library written in Swift featuring combinators like map, flatMap, whenAll, whenAny.
Swift
68
star
5

CoffeeSharp

CoffeeScript compilation for Windows
F#
57
star
6

AwesomePrelude

Yet another alternative Haskell Prelude, but this one is awesome!
Haskell
51
star
7

language-cil

Manipulating Common Intermediate Language AST in Haskell
Haskell
20
star
8

swift-cancellationtoken

CancellationToken in Swift, modelled after the .NET version
Swift
20
star
9

Statham

Swift library for decoding JSON
Swift
11
star
10

FunVM

A Functional intermediate language
Haskell
9
star
11

ScorchedCanvas

Multiplayer Scorched Earth clone!
JavaScript
8
star
12

bool-extras

A fold function for Bool in Haskell
Haskell
7
star
13

wol

A program and library to a send WoL Magic Packet, to remotely start a computer.
Haskell
5
star
14

feed2twitter

Send posts from a feed to Twitter
Haskell
4
star
15

codeanalysis-checknullable

Experimental Roslyn diagnostic extension
C#
4
star
16

jquery.event.combinators

jQuery Event Combinators
JavaScript
3
star
17

Datum

Swift library that makes dealing with timezone information explicit
Swift
3
star
18

codeanalysis-checkdependencyproperty

Experimental Roslyn diagnostic extension
C#
3
star
19

helloworld

An experimation project
Haskell
2
star
20

hackage2twitter

Send new Hackage releases to Twitter
Haskell
2
star
21

promises.js

Experimental JavaScript library for promises
JavaScript
2
star
22

dutchhug-nl

source code of DutchHUG.nl website
Haskell
2
star
23

PromissumAlamofire

Alamofire promise extensions
Swift
1
star
24

CatalystFullScreenVideo

Demo project showing full screen video in a Mac Catalyst app
Swift
1
star