How to do it...

  1. Let's continue using our previous demo to add a way to share the contact information when a user clicks on it.
  2. Let's start by handling the selection of cells in a table view. Override the following function in UITableViewDelegate:
      func tableView(_ tableView: UITableView, didSelectRowAt        indexPath: IndexPath) {           let contact = self.contacts[indexPath.row]           self.shareContact(contact: contact)       } 
  1. Add the following function to share the content:
      func shareContact(contact: Contact){           let contactInfo = "Name: (contact.firstName)             (contact.lastName) nEmail: (contact.email)n              Cell phone: (contact.cellPhone)"           let photoImageURL = URL(string: contact.pictureURLString)                    let activityViewController = UIActivityViewController(activityItems: ...

Get iOS Programming Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.