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

# MCPeerID

An  `MCPeerID` object represents a peer in a multipeer session.

```
class MCPeerID
```

## Overview

You create a single peer ID object that represents the instance of your app running on the local device. The Multipeer Connectivity framework is responsible for creating peer ID objects that represent other devices.

To create a new peer ID for the local app and associate a display name with that ID, call [`init(displayName:)`](/documentation/MultipeerConnectivity/MCPeerID/init(displayName:)). The peer’s name must be no longer than 63 bytes in UTF-8 encoding.

Each peer ID your app creates with [`init(displayName:)`](/documentation/MultipeerConnectivity/MCPeerID/init(displayName:)) is unique, even when supplying the same display name. If you want a device’s peer ID to be stable over time, don’t create a new peer ID every time your app begins advertising or browsing. Instead, archive the ID when you create it, and then unarchive it the next time you need it. If you need the peer ID to be tied to the display name, you can archive the name as well, and only create a new peer ID when the name changes, as illustrated in the following code fragment:

```objc
NSString *displayName = <#Get a name#>;
 
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *oldDisplayName = [defaults stringForKey:kDisplayNameKey];
MCPeerID *peerID;
 
if ([oldDisplayName isEqualToString:displayName]) {
    NSData *peerIDData = [defaults dataForKey:kPeerIDKey];
    peerID = [NSKeyedUnarchiver unarchiveObjectWithData:peerIDData];
} else {
    peerID = [[MCPeerID alloc] initWithDisplayName:displayName];
    NSData *peerIDData = [NSKeyedArchiver archivedDataWithRootObject:peerID];
    [defaults setObject:peerIDData forKey:kPeerIDKey];
    [defaults setObject:displayName forKey:kDisplayNameKey];
    [defaults synchronize];
}
```

## Topics

### Peer Methods

[`init(displayName:)`](/documentation/MultipeerConnectivity/MCPeerID/init(displayName:))

Initializes a peer.

[`displayName`](/documentation/MultipeerConnectivity/MCPeerID/displayName)

The display name for this peer.



---

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)