title: How to view the MCBrowserViewController in the Multipeer Connectivity framework using swift 4
body: <p>i have been trying to get Multipeer connectivity to work IN SWIFT 4, but i cant view the MCBrowserViewController, I’m new to swift so can anyone help? I also am aiming to make this, <a href="https://www.hackingwithswift.com/example-code/system/how-to-create-a-peer-to-peer-network-using-the-multipeer-connectivity-framework" rel="nofollow noreferrer">https://www.hackingwithswift.com/example-code/system/how-to-create-a-peer-to-peer-network-using-the-multipeer-connectivity-framework</a>
  So pretty much I’m aiming to make a peer to peer connection programically.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>import UIKit
  import PlaygroundSupport
  import MultipeerConnectivity
  var peerID: MCPeerID!
  var mcSession: MCSession!
  var mcAdvertiserAssistant: MCAdvertiserAssistant!
  var browser: MCNearbyServiceBrowser!
  var foundPeers = [MCPeerID]()
  class viewcontroller: UIViewController {
  override func viewDidLoad() {
  
  
  peerID = MCPeerID(displayName: UIDevice.current.name)
  mcSession = MCSession(peer: peerID, securityIdentity: nil,       encryptionPreference: .none)
  mcSession.delegate.self
  
  class ViewController: UIViewController, MCSessionDelegate, MCBrowserViewControllerDelegate {
  
  
  
      let session = MCSession(peer: peerID, 
                              securityIdentity: nil, 
                              encryptionPreference: .none)
  
  
  
      func session(_ session: MCSession, peer peerID: MCPeerID, didChange state: MCSessionState) {
          switch state {
          case MCSessionState.connected:
              print("Connected: \(peerID.displayName)")
          case MCSessionState.connecting:
              print("Connecting: \(peerID.displayName)")
          case MCSessionState.notConnected:
              print("Not Connected: \(peerID.displayName)")
          }
      }
  
      func browser(browser: MCNearbyServiceBrowser!, foundPeer peerID: MCPeerID!, withDiscoveryInfo info: [NSObject : AnyObject]!) {
          foundPeers.append(peerID)
  
          print(browser)
      }
  
  
      func session(_ session: MCSession, didReceive data: Data, fromPeer peerID: MCPeerID) {
          if let image = UIImage(data: data) {
              DispatchQueue.main.async { [unowned self] in
                  print("image recieved")
              }
          }
      }
      func sendImage(img: UIImage) {
          if mcSession.connectedPeers.count &gt; 0 {
              if let imageData = UIImagePNGRepresentation(img) {
                  do {
                      try mcSession.send(imageData, toPeers: mcSession.connectedPeers, with: .reliable)
                  } catch let error as NSError {
                      let ac = UIAlertController(title: "Send error", message: error.localizedDescription, preferredStyle: .alert)
                      ac.addAction(UIAlertAction(title: "OK", style: .default))
                      present(ac, animated: true)
                  }
              }
          }
      }
  
      func session(_ session: MCSession, didReceive stream: InputStream, withName streamName: String, fromPeer peerID: MCPeerID) {
      }
      func session(_ session: MCSession, didStartReceivingResourceWithName resourceName: String, fromPeer peerID: MCPeerID, with progress: Progress) {
      }
          func session(_ session: MCSession, didFinishReceivingResourceWithName resourceName: String, fromPeer peerID: MCPeerID, at localURL: URL?, withError error: Error?) {
          }
      func browserViewControllerDidFinish(_ browserViewController: MCBrowserViewController) {
                  dismiss(animated: true)
              }
      func browserViewControllerWasCancelled(_ browserViewController: MCBrowserViewController) {
          dismiss(animated: true)
      }
  
  
      func startHosting(action: UIAlertAction!) {
          mcAdvertiserAssistant = MCAdvertiserAssistant(serviceType: "hws-ridleyn", discoveryInfo: nil, session: mcSession)
          mcAdvertiserAssistant.start()
      }
      func joinSession(action: UIAlertAction!) {
          let mcBrowser = MCBrowserViewController(serviceType: "hws-ridleyn", session: mcSession)
          mcBrowser.delegate = self
          present(mcBrowser, animated: true)
      }
  
      let vc = UIToolbar(frame: CGRect(x: 100, y: 100, width: 200, height: 200))
  
  
      // your view controller here
  }
  let vcc = ViewController()
  vcc.startHosting(action: nil)
  ViewController.startHosting(vcc)
  
    }
  }
     PlaygroundPage.current
  
  
  func presentViewControllerAsSheet(_ viewController: MCBrowserViewController) {
  
  }
  </code></pre>