How to do it...

  1. Create a new Xcode project with the Single View Application template and name it NetworkingDemo.
  1. Let's add a button at the center of the screen so that when a user clicks on it, we will trigger a server connection to fetch some data.
  2. Open Main.storyboard and add a button at the center, with the title Connect:
  1. Link an IBOutlet and IBAction to the button, as follows:
      @IBOutlet weak var connectButton: UIButton!       @IBAction func didClickOnConnectButton(_ sender: Any) {       }
  1. Now, create a new Swift file for a new class called ContactsManager. This class will be responsible for fetching contacts information from a server.

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.