title: PeerId (MCPeerID) customization
body: <p>I recently have built a fully functional multipeer connectivity app and have had some trouble trying to find a way to allow my users to <em>change</em> (or create) a personal <strong>peerId</strong>. The <strong>MCBrowserViewController</strong> picks up devices connected to the same wifi network but only displays their device name and doesn't allow for users to create their own username. How best should I go about this? I have tried <strong>initWithDisplayName()</strong> to no avail and have found no resources pertaining to this written in <em>Swift</em> only in Objective-C. </p>
  
  <pre><code>import UIKit
  import MultipeerConnectivity
  
  class ViewController: UIViewController, MCBrowserViewControllerDelegate, MCSessionDelegate {
  
  let serviceType = "LCOC-Chat"
  
  var browser : MCBrowserViewController!
  var assistant : MCAdvertiserAssistant!
  var session : MCSession!
  var peerID: MCPeerID!
  
  @IBOutlet var chatView: UITextView!
  @IBOutlet var messageField: UITextField!
  
  override func viewDidLoad() {
      super.viewDidLoad()
  
      self.peerID = MCPeerID(displayName: UIDevice.currentDevice().name)
      self.session = MCSession(peer: peerID)
      self.session.delegate = self
  
      // create the browser viewcontroller with a unique service name
      self.browser = MCBrowserViewController(serviceType:serviceType,
          session:self.session)
  
      self.browser.delegate = self;
  
      self.assistant = MCAdvertiserAssistant(serviceType:serviceType,
          discoveryInfo:nil, session:self.session)
  
      // tell the assistant to start advertising our fabulous chat
      self.assistant.start()
  }
  
  @IBAction func sendChat(sender: UIButton) {
      // Bundle up the text in the message field, and send it off to all
      // connected peers
  
      let msg = self.messageField.text.dataUsingEncoding(NSUTF8StringEncoding,
          allowLossyConversion: false)
  
      var error : NSError?
  
      self.session.sendData(msg, toPeers: self.session.connectedPeers,
          withMode: MCSessionSendDataMode.Unreliable, error: &amp;error)
  
      if error != nil {
          print("Error sending data: \(error?.localizedDescription)")
      }
  
      self.updateChat(self.messageField.text, fromPeer: self.peerID)
  
      self.messageField.text = ""
  }
  
  func updateChat(text : String, fromPeer peerID: MCPeerID) {
      // Appends some text to the chat view
  
      // If this peer ID is the local device's peer ID, then show the name 
      // as "Me"
      var name : String
  
      switch peerID {
      case self.peerID:
          name = "Me"
      default:
          name = peerID.displayName
      }
  
      // Add the name to the message and display it
      let message = "\(name): \(text)\n"
      self.chatView.text = self.chatView.text + message
  
  }
  
  @IBAction func showBrowser(sender: UIButton) {
      // Show the browser view controller
      self.presentViewController(self.browser, animated: true, completion: nil)
  }
  
  func browserViewControllerDidFinish(
      browserViewController: MCBrowserViewController!)  {
      // Called when the browser view controller is dismissed (ie the Done 
      // button was tapped)
  
      self.dismissViewControllerAnimated(true, completion: nil)
  }
  
  func browserViewControllerWasCancelled(
      browserViewController: MCBrowserViewController!)  {
      // Called when the browser view controller is cancelled
  
      self.dismissViewControllerAnimated(true, completion: nil)
  }
  
  func session(session: MCSession!, didReceiveData data: NSData!,
      fromPeer peerID: MCPeerID!)  {
      // Called when a peer sends an NSData to us
  
      // This needs to run on the main queue
      dispatch_async(dispatch_get_main_queue()) {
  
          var msg = NSString(data: data, encoding: NSUTF8StringEncoding)
  
          self.updateChat(msg, fromPeer: peerID)
      }
  }
  
  // The following methods do nothing, but the MCSessionDelegate protocol 
  // requires that we implement them.
  func session(session: MCSession!,
      didStartReceivingResourceWithName resourceName: String!,
      fromPeer peerID: MCPeerID!, withProgress progress: NSProgress!)  {
  
      // Called when a peer starts sending a file to us
  }
  
  func session(session: MCSession!,
      didFinishReceivingResourceWithName resourceName: String!,
      fromPeer peerID: MCPeerID!,
      atURL localURL: NSURL!, withError error: NSError!)  {
      // Called when a file has finished transferring from another peer
  }
  
  func session(session: MCSession!, didReceiveStream stream: NSInputStream!,
      withName streamName: String!, fromPeer peerID: MCPeerID!)  {
      // Called when a peer establishes a stream with us
  }
  
  func session(session: MCSession!, peer peerID: MCPeerID!,
      didChangeState state: MCSessionState)  {
      // Called when a connected peer changes state (for example, goes offline)
  
      }
   }
  </code></pre>