     }
 }
 
-
-
+// MARK: - Extensions
+
+private var selectedEmailKey: UInt8 = 0
+private extension CNContact {
+    var userSelectedEmail: String? {
+        get { return objc_getAssociatedObject(self, &selectedEmailKey) as? String }
+        set { objc_setAssociatedObject(self, &selectedEmailKey, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN) }
+    }
+
+    var displayString: String {
+        guard !givenName.isEmpty || !familyName.isEmpty else {
+            if let email = emailAddresses.first?.value {
+                return email as String
+            }
+            return ""
+        }
+        return "\(givenName) \(familyName)"
+    }
+    
+    var thumbnailImage: UIImage? {
+        guard let data = thumbnailImageData else { return nil }
+        return UIImage(data: data)
+    }
+}
 
 private extension CNContactStore {
     static func fetchAllContacts(keysToFetch: [CNKeyDescriptor], filter: ((CNContact) -> Bool)? = nil, completion: @escaping (([CNContact]?, NSError?) -> Void)) {

        let contact = filteredContacts[indexPath.row]
        let isSelected = selectedContacts.contains(contact)

        cell.thumbnailImageView.image = contact.thumbnail
        cell.label.text = "\(contact.givenName) \(contact.familyName)"
        cell.accessoryType = isSelected ? .checkmark : .none
        return cell
    }

        addConstraintsForTableView()
        addConstraintsForLoadingSpinner()
    }
}

// MARK: - Cell
