title: NSStoryboardSegue sample code (Yosemite Storyboard)
body: <p>OS X Yosemite introduced <strong>NSStoryboardSegue</strong></p>
  
  <p><a href="https://developer.apple.com/library/mac/documentation/AppKit/Reference/NSStoryboardSegue_Class/occ/instm/NSStoryboardSegue/perform" rel="nofollow noreferrer"><em>“A storyboard segue specifies a transition or containment relationship between two scenes in a storyboard…”</em></a></p>
  
  <hr>
  
  <p><strong>Update:</strong></p>
  
  <p>• If I attempt to use a NSStoryboardSegue subclass in a Storyboard with Yosemite., it crashes with SIGABRT.</p>
  
  <p>• If I ignore segues, and manually present a view controller using a specified, custom animator for presentation and dismissal, </p>
  
  <pre><code>func presentViewController(_ viewController: NSViewController,
                    animator animator: NSViewControllerPresentationAnimator)
  </code></pre>
  
  <p>it works as expected. </p>
  
  <hr>
  
  <p>This post provides additional insight: <a href="https://stackoverflow.com/questions/26715636/animate-custom-presentation-of-viewcontroller-in-os-x-yosemite">Animate custom presentation of ViewController in OS X Yosemite</a></p>
  
  <p>Using that as a reference, here's my attempt so far: </p>
  
  <pre><code>class FadeSegue: NSStoryboardSegue {
  
      override func perform() {
          super.perform()
          sourceController.presentViewController(destinationController as NSViewController,
              animator: FadeTransitionAnimator())
      }
  }
  
  
  class FadeTransitionAnimator: NSObject, NSViewControllerPresentationAnimator {
  
      func animatePresentationOfViewController(toViewController: NSViewController, fromViewController: NSViewController) {
  
          toViewController.view.wantsLayer = true
          toViewController.view.layerContentsRedrawPolicy = .OnSetNeedsDisplay
          toViewController.view.alphaValue = 0
          fromViewController.view.addSubview(toViewController.view)
          toViewController.view.frame = fromViewController.view.frame
  
          NSAnimationContext.runAnimationGroup({ context in
              context.duration = 2
              toViewController.view.animator().alphaValue = 1
              }, completionHandler: nil)
      }
  
      func animateDismissalOfViewController(viewController: NSViewController, fromViewController: NSViewController) {
  
          viewController.view.wantsLayer = true
          viewController.view.layerContentsRedrawPolicy = .OnSetNeedsDisplay
  
          NSAnimationContext.runAnimationGroup({ (context) -&gt; Void in
              context.duration = 2
              viewController.view.animator().alphaValue = 0
              }, completionHandler: {
                  viewController.view.removeFromSuperview()
          })
      }
  
  }
  </code></pre>