Closure(Best One)

PHOTO EMBED

Wed Jun 15 2022 07:10:53 GMT+0000 (Coordinated Universal Time)

Saved by @hasnat #ios #swift #closure

// calling      
UpdateProfileData(dataToUpdate) { (isUpdated) in
            if isUpdated {
                self.aboutTableView.reloadData()
                print("updatedd")
            }
        }

func UpdateProfileData (_ dateToUpdate: [String: Any], completionHandler:@escaping (_ success:Bool) -> Void) {
        
        SVProgressHUD.show()
        let User = Auth.auth().currentUser
        guard let user = User else {
            print("Error45")
            SVProgressHUD.dismiss()
            return
        }
        let db = Firestore.firestore()
        db.collection("Users").document(user.uid).setData(dateToUpdate, merge: true) { (error) in
            if error != nil {
                print("Error99")
                SVProgressHUD.dismiss()
                return
            }
            print("updated")
            completionHandler(true)
            SVProgressHUD.dismiss()
        }
    }
content_copyCOPY