<!--
{
  "availability" : [
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "WatchKit",
  "identifier" : "/documentation/WatchKit/WKInterfaceController/contextForSegue(withIdentifier:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "WatchKit"
    ],
    "preciseIdentifier" : "c:objc(cs)WKInterfaceController(im)contextForSegueWithIdentifier:"
  },
  "title" : "contextForSegue(withIdentifier:)"
}
-->

# contextForSegue(withIdentifier:)

Returns the context object to pass to the specified interface controller when a button is tapped.

```
func contextForSegue(withIdentifier segueIdentifier: String) -> Any?
```

## Parameters

`segueIdentifier`

The identifier of the segue that was triggered. When configuring your interface, specify the identifier for a segue in the Attributes inspector.

## Return Value

The object to pass to the new interface controller. Use this object to communicate important information to the new interface controller, such as the data to be displayed or any relevant state information. You may return `nil` if you want, but doing so is not recommended.

## Discussion

When you create a segue from a button to a single interface controller, the system calls this method when that segue is triggered. Use this method to provide the new interface controller with any contextual data it needs to display its content. The object you return is passed directly to the new interface controller’s [`awake(withContext:)`](/documentation/WatchKit/WKInterfaceController/awake(withContext:)) method.

WatchKit calls this method on your WatchKit extension’s main thread. Implementation of this method is optional but is recommended if you use segues in your storyboard file. You do not need to call `super` in your implementation. For segues originating from a table row, use the [`contextForSegue(withIdentifier:in:rowIndex:)`](/documentation/WatchKit/WKInterfaceController/contextForSegue(withIdentifier:in:rowIndex:)) method instead.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)