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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.