Easy dependency injection for storyboard segues
Branch: master
Clone or download
sharplet Add missing @escaping annotation
This should have been escaping all along, and fixes a compile error in Xcode 10.
Latest commit ddc1b4d Jun 27, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Perform.xcodeproj Remove duplicated build setting values Jun 27, 2018
Sources/Perform Add missing @escaping annotation Jun 27, 2018
Tests Migrate to Swift 3 Apr 6, 2017
bin Mark bin/update as executable Aug 30, 2016
.gitignore Add Podfile for testing Sep 12, 2016
.swift-version Convince CocoaPods to lint with Swift 3 Apr 6, 2017
CONTRIBUTING.md Add README, LICENSE and CONTRIBUTING Sep 7, 2016
Cartfile
Cartfile.private
Cartfile.resolved Update dependencies Jun 27, 2018
LICENSE Add README, LICENSE and CONTRIBUTING Sep 7, 2016
Perform.podspec Dynamically get podspec version from latest git tag Apr 6, 2017
Podfile
README.md Update version compatibility documentation for 2.0 Apr 6, 2017
circle.yml Use Xcode 8.3 on CI Apr 6, 2017

README.md

Perform

Easy dependency injection for storyboard segues.

import Perform

// ...

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: NSIndexPath) {
  let task = taskList[indexPath.row]
  perform(.showTaskDetails) { taskVC in
    taskVC.task = task
  }
}

Usage

Configure your segues:

// Sources/Extensions/Segue.swift
import Perform

extension Segue {
  static var showTaskDetails: Segue<TaskDetailsViewController> {
    return .init(identifier: "ShowTaskDetails")
  }
}

And then use perform(_:prepare:) instead of performSegue(withIdentifier:sender:). That's it!

Type-safe segues

Perform checks the type of the destination view controller and casts it for you, raising an error if your destination view controller is an unexpected type.

Still works if your view controller is embedded in a container

Ever written code like this?

guard let nav = segue.destinationViewController as? UINavigationController,
  let content = nav.rootViewController as? MyViewController
  else { return }

// ... finally! 😭

Perform takes care of this, searching the view controller hierarchy for a view controller of the matching type!

No switch statements in prepareForSegue(_:sender:)

Multiple segues from one view controller? No problem, just prepare each destination view controller right where you perform the segue. No more massive switch statements.

Further reading

For more examples, and a discussion about the motivation and design of Perform, take a look at the introductory blog post.

Installation

Compatibility

Swift Version Perform Version
3.x 2.x
2.x 1.x

Carthage

Add the following to your Cartfile:

github "thoughtbot/Perform" ~> 2.0

Then run carthage update Perform.

Follow the instructions in Carthage's README for up-to-date installation instructions.

CocoaPods

Add the following to your Podfile:

pod "Perform", "~> 2.0"

See the CocoaPods guide for up-to-date installation instructions.

Contributing

See the CONTRIBUTING document.

License

Perform is Copyright (c) 2016 thoughtbot, inc. It is free software, and may be redistributed under the terms specified in the LICENSE file.

About

thoughtbot

Perform is maintained and funded by thoughtbot, inc. The names and logos for thoughtbot are trademarks of thoughtbot, inc.

We love open source software! See our other projects or hire us to help build your product.