---
title: "connectPeer(_:withNearbyConnectionData:)"
framework: multipeerconnectivity
role: symbol
role_heading: Instance Method
path: "multipeerconnectivity/mcsession/connectpeer(_:withnearbyconnectiondata:)"
---

# connectPeer(_:withNearbyConnectionData:)

Call this method to connect a peer to the session when using your own service discovery code instead of an  MCNearbyServiceBrowser or MCBrowserViewController object.

## Declaration

```swift
func connectPeer(_ peerID: MCPeerID, withNearbyConnectionData data: Data)
```

## Parameters

- `peerID`: The peer ID object obtained from the nearby peer.
- `data`: The connection data object obtained from the nearby peer.

## Discussion

Discussion Call this method to connect to peers when you are using your own service discovery code instead of an MCNearbyServiceBrowser or MCBrowserViewController object. For more information, see the Managing Peers Manually section in the overview of the MCSession class reference.

## See Also

### Managing Peers Manually

- [cancelConnectPeer(_:)](multipeerconnectivity/mcsession/cancelconnectpeer(_:).md)
- [connectedPeers](multipeerconnectivity/mcsession/connectedpeers.md)
- [nearbyConnectionData(forPeer:withCompletionHandler:)](multipeerconnectivity/mcsession/nearbyconnectiondata(forpeer:withcompletionhandler:).md)
