<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/RunLoop/add(_:forMode:)-6z982",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSRunLoop(im)addPort:forMode:"
  },
  "title" : "add(_:forMode:)"
}
-->

# add(_:forMode:)

Adds a port as an input source to the specified mode of the run loop.

```
func add(_ aPort: Port, forMode mode: RunLoop.Mode)
```

## Parameters

`aPort`

The port to add to the receiver.

`mode`

The mode in which to add `aPort`. You may specify a custom mode or use one of the modes listed in `Run Loop Modes`.

## Discussion

This method schedules the port with the receiver. You can add a port to multiple input modes. When the receiver is running in the specified mode, it dispatches messages destined for that port to the port’s designated handler routine.

---

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)