<!--
{
  "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/MCPeerID/init(displayName:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Multipeer Connectivity"
    ],
    "preciseIdentifier" : "c:objc(cs)MCPeerID(im)initWithDisplayName:"
  },
  "title" : "init(displayName:)"
}
-->

# init(displayName:)

Initializes a peer.

```
init(displayName myDisplayName: String)
```

## Parameters

`myDisplayName`

The display name for the local peer. If you use the multipeer browser view controller, this name is shown.

    The display name is intended for use in UI elements, and should be short and descriptive of the local peer. The maximum allowable length is 63 bytes in UTF-8 encoding. The     `displayName`     parameter may not be     `nil`     or an empty string.

## Return Value

An initialized peer ID object.

## Discussion

Call this method *only* when creating the local peer, not when you create objects that represent other devices.

This method throws an exception if the `displayName` value is too long, empty, or `nil`.

Each call to this method produces a unique peer ID, even for the same display name. If you need a device to maintain a consistent peer ID over time, you may want to archive and reuse it later instead of creating a new one every time your app starts advertising or browsing.

---

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)