eliable way to match an MCPeerID across notifications — is identity comparison safe?

I have a MultipeerConnectivity-based app where a view controller is opened for a specific connected peer. When data arrives for that peer, my networking manager posts a Notification whose userInfo carries the sender's MCPeerID, and the view controller filters updates like this: guard let incomingPeerID = userInfo["peerID"] as? MCPeerID, incomingPeerID == self.peerID else { return } // apply update…

Answered by DTS Engineer in 895405022

MCPeerID is effectively a large random number that the remote peer generates and assigns to itself. You can think of it like a UUID. Thus, it’s fine for you, as the local peer, to compare it for equality. It’s also hashable, so you can use it as a dictionary key.

IMPORTANT Xcode 27 beta has officially deprecated Multipeer Connectivity. If you’re writing new code, I recommend that you not use this framework. If you have existing code, start planning your move off it. For concrete advice on how to do this, see Moving from Multipeer Connectivity to Network Framework.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

MCPeerID is effectively a large random number that the remote peer generates and assigns to itself. You can think of it like a UUID. Thus, it’s fine for you, as the local peer, to compare it for equality. It’s also hashable, so you can use it as a dictionary key.

IMPORTANT Xcode 27 beta has officially deprecated Multipeer Connectivity. If you’re writing new code, I recommend that you not use this framework. If you have existing code, start planning your move off it. For concrete advice on how to do this, see Moving from Multipeer Connectivity to Network Framework.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

eliable way to match an MCPeerID across notifications — is identity comparison safe?
 
 
Q