Using the data that's received on the detail page is pretty straightforward. We need to add some @IBOutlets and a contact property. Then, we will use the information available in the contact at an appropriate time to show it to the user. Finally, the created outlets should be hooked up through the Interface Builder.
Let's take a look at the following required code first:
@IBOutlet var contactPhoneLabel: UILabel!
@IBOutlet var contactEmailLabel: UILabel!
@IBOutlet var contactAddressLabel: UILabel!
var contact: HCContact?
override func viewDidLoad() {
// current implementation...
if let contact = self.contact {
contact.fetchImageIfNeeded()
contactImage.image = contact.contactImage
contactNameLabel.text = "\(contact.givenName) \(contact.familyName)"
contactPhoneLabel.text = contact.phoneNumber
contactEmailLabel.text = contact.emailAddress
contactAddressLabel.text = contact.address
}
}
This code should be added to the ContactDetailViewController.swift file. The first part declares the outlets and the contact property. The additions to viewDidLoad first check that the contact is actually set and then assign the values to the user interface elements.
The final step is to go to the storyboard, select the detail view controller, and connect the outlets in the Connections Inspector to the user interface elements. After doing this, build and run your app to see the detail page in its full glory. Now, let's add some icing to this cake by implementing peek and pop using 3D Touch!