title: Request Access To Contacts in Swift 3
body: <p>I want to access the user's Contacts and am planning to do so using the Contacts and ContactsUI framework that Apple supplies.</p>
  
  <p>First, though, I need to ask permission to access the user's contacts and am having trouble doing so. In Swift 2, one could ask permission like so:</p>
  
  <pre><code>func requestForAccess(completionHandler: (accessGranted: Bool) -&gt; Void) {
      let authorizationStatus = CNContactStore.authorizationStatusForEntityType(CNEntityType.Contacts)
  
      switch authorizationStatus {
      case .Authorized:
          completionHandler(accessGranted: true)
  
      case .Denied, .NotDetermined:
          self.contactStore.requestAccessForEntityType(CNEntityType.Contacts, completionHandler: { (access, accessError) -&gt; Void in
              if access {
                  completionHandler(accessGranted: access)
              }
              else {
                  if authorizationStatus == CNAuthorizationStatus.Denied {
                      dispatch_async(dispatch_get_main_queue(), { () -&gt; Void in 
                          let message = "\(accessError!.localizedDescription)\n\nPlease allow the app to access your contacts through the Settings."
                          self.showMessage(message)
                      })
                  }
              }
          })
  
      default:
          completionHandler(accessGranted: false)
      }
  }
  </code></pre>
  
  <p>I tried to convert it to Swift 3 like so, but am still coming up with errors. The error is "Instance member 'async' cannot be used on type 'DispatchQueue'; did you mean to use a value of this type instead?":</p>
  
  <pre><code>func requestForAccess(completionHandler: @escaping (_ accessGranted: Bool) -&gt; Void) {
      let authorizationStatus = CNContactStore.authorizationStatus(for: CNEntityType.contacts)
  
      switch authorizationStatus {
      case .authorized:
          completionHandler(true)
  
      case .denied, .notDetermined:
          self.contactStore.requestAccess(for: CNEntityType.contacts, completionHandler: { (access, accessError) -&gt; Void in
              if access {
                  completionHandler(access)
              }
              else {
                  if authorizationStatus == CNAuthorizationStatus.denied {
                      DispatchQueue.async(group: DispatchQueue.main, execute: { () -&gt; Void in //error here
                          let message = "\(accessError!.localizedDescription)\n\nPlease allow the app to access your contacts through the Settings."
                          self.showMessage(message)
                      })
                  }
              }
          })
  
      default:
          completionHandler(false)
      }
  }
  </code></pre>
  
  <p>Can anyone help out to try to fix this? Any help would be immensely appreciated. Thanks a ton in advance. </p>
  
  <p>Cheers,
  Theo</p>