             
             strongSelf.searchedContacts = strongSelf.contacts
             //            weak var weakSelf = self
-            DispatchQueue.main.async{
+            DispatchQueue.main.async {
                 strongSelf.loadingView.isHidden = true
                 strongSelf.activityIndicatorView.stopAnimating()
                 strongSelf.tblView.reloadData()


fileprivate class ContactCell: UITableViewCell {
    
    let checkMarkLabel = UILabel(frame: CGRect(x: 8, y: 12, width: 22, height: 22))
    let nameLabel = UILabel(frame: CGRect(x: 45, y: 6, width: UIScreen.main.bounds.size.width-45-8, height: 18))
    let mobileLable = UILabel(frame: CGRect(x: 45, y: 24, width: UIScreen.main.bounds.width-45-8, height: 15))
    
    func initialize() {
        super.awakeFromNib()
        
        checkMarkLabel.textColor = UIColor.black
        checkMarkLabel.text = "☐"
        checkMarkLabel.font = UIFont.systemFont(ofSize: 15)
        self.addSubview(checkMarkLabel)
        
        nameLabel.textColor = UIColor.black
        nameLabel.font = UIFont.systemFont(ofSize: 15)

        }
        searchBar.resignFirstResponder()
        
        if maxCount > 1 {
            let cell : ContactCell = tableView.cellForRow(at: indexPath) as! ContactCell
            
            if !pickedContacts.contains(where: { (contact) -> Bool in
                if contact == [LocalConstants.ContactNameKey : contactAtIndex[LocalConstants.ContactNameKey]!, LocalConstants.ContactPhoneKey : contactAtIndex[LocalConstants.ContactNumberKey]!] {
                    return true
                }
                
                return false
            }) {
                if pickedContacts.count < maxCount {
                    cell.checkMarkImageView.image = checkImage
                    cell.checkMarkImageView.adjustImage()
                    pickedContacts.append([LocalConstants.ContactNameKey : contactAtIndex[LocalConstants.ContactNameKey]!, LocalConstants.ContactPhoneKey : contactAtIndex[LocalConstants.ContactNumberKey]!])
                }
                else {
                    cell.shake()
                }
            }
            else {
                cell.checkMarkImageView.image = uncheckImage
                cell.checkMarkImageView.adjustImage()
                if let index = pickedContacts.index(where: { (contact) -> Bool in
                    if contact == [LocalConstants.ContactNameKey : contactAtIndex[LocalConstants.ContactNameKey]!, LocalConstants.ContactPhoneKey : contactAtIndex[LocalConstants.ContactNumberKey]!] {
                        return true
                    }
                    
                    return false
                }) {
                    pickedContacts.remove(at: index)
                }
            }
        }
        else {
            dismiss(animated: true, completion: nil)
            delegate?.pickedContacts(contacts: [Contact(name: contactAtIndex[LocalConstants.ContactNameKey]!, mobile: contactAtIndex[LocalConstants.ContactNumberKey]!)])
        }
    }
    
    func scrollViewWillBeginDecelerating(_ scrollView: UIScrollView) {
        searchBar.resignFirstResponder()
    }
}
