return of function always 0



I have this functions made:


func checkUser() ->Int {
        let myContainer = CKContainer.default()
        let privateDatabase = myContainer.privateCloudDatabase
        let publicDatabase = myContainer.publicCloudDatabase
        let recordID = CKRecordID(recordName: "admin")
        myContainer.publicCloudDatabase.fetch(withRecordID: recordID) { (record, error) in
            if let r = record {
                self.userCount = 1
                print("user: (r["username"])")
            if let e = error {
                self.userCount = 0
                print("ERROR: (e)")
        return self.userCount


and its return always 0 because its return first self.userCount and after this it goes in if / else loop

It would be a great help if somebody say what I made wrong, i sit here 2 days on one function




Powered by WPeMatico


You may also like...

Comments are closed.