<!--
{
  "availability" : [
    "iOS: 7.0.0 - 27.0.0",
    "iPadOS: 7.0.0 - 27.0.0",
    "macCatalyst: 13.1.0 - 27.0.0",
    "macOS: 10.10.0 - 27.0.0",
    "tvOS: 10.0.0 - 27.0.0",
    "visionOS: 1.0.0 - 27.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "MultipeerConnectivity",
  "identifier" : "/documentation/MultipeerConnectivity/MCNearbyServiceBrowser/init(peer:serviceType:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Multipeer Connectivity"
    ],
    "preciseIdentifier" : "c:objc(cs)MCNearbyServiceBrowser(im)initWithPeer:serviceType:"
  },
  "title" : "init(peer:serviceType:)"
}
-->

# init(peer:serviceType:)

Initializes the nearby service browser object.

```
init(peer myPeerID: MCPeerID, serviceType: String)
```

## Parameters

`myPeerID`

The local peer ID for this instance.

`serviceType`

The type of service to search for. This should be a *short* text string that describes the app’s networking protocol, in the same format as a Bonjour service type (without the transport protocol) and meeting the restrictions of [RFC 6335](https://tools.ietf.org/html/rfc6335) (section 5.1) governing Service Name Syntax. In particular, the string:

- Must be 1–15 characters long
- Can contain only ASCII lowercase letters, numbers, and hyphens
- Must contain at least one ASCII letter
- Must not begin or end with a hyphen
- Must not contain hyphens adjacent to other hyphens.

    This name should be easily distinguished from unrelated services. For example, a text chat app made by ABC company could use the service type     `abc-txtchat`    .

    For more details, read     [Domain Naming Conventions](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/NetServices/Articles/domainnames.html#//apple_ref/doc/uid/TP40002460)    .

## Return Value

Returns an initialized nearby service browser object, or `nil` if an error occurs.

## Discussion

This method throws an exception if the `session` or `serviceType` parameters do not contain valid objects or the specified Bonjour service type is not valid.

---

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)