Завершите функции для элемента, прежде чем переходить к следующему элементу в массиве. iOS - PullRequest
0 голосов
/ 14 января 2020

У меня есть список идентификаторов, для которых я хочу завершить набор функций, каждый идентификатор извлекается из массива, а затем вызывается группа функций в l oop, у меня есть очередь отправки в l oop, но, кажется, он слишком быстро проходит через l oop, и до того, как он завершил выполнение функций для идентификатора, он изменил идентификатор циклически, таким образом отправляя данные из функций в неправильные места.

Идентификаторы должны быть одинаковыми до тех пор, пока все функции в l oop fini sh и затем снова не запустить l oop с новыми идентификаторами.

где я ошибаюсь?

func sendToDBProject(completion: @escaping (_ finished: Bool) -> ()) {
    self.setDate()
    for i in artistFinal {
        dispatchGroup.enter()
        idG = i.key
         print("Tony hit artist db send the artist id is \(idG)")
        let datesForMessageTemp = artistFinal[idG] as! [String]
        datesForMessage = datesForMessageTemp.joined(separator: " - ")
        userIDNum = idG
        emailAddress.append(userIDNum)
        print("Tony the id is userIDNum \(userIDNum)")
        self.getMessagesCount(completion: { (complete) in
            print("Tony got to end message num artist")
            self.getProjects(completion: { (complete) in
                print("Tony got to end get projects num artist")
                self.sendToDBUserMessage(completion: { (complete) in
                    print("Tony got to end message snt artist")
                    self.updateBadgeNum(completion: { (complete) in
                        print("Tony got messages count")
                        print("Tony ther status is \(self.statusToSet)")
                        if self.statusToSet == "Released" {
                            self.updateUserProjDBRelease(completion: { (complete) in
                                print("Tony got to end release artist")

                                self.dispatchGroup.leave()
                            })
                        }else if self.statusToSet == "Pencil" {

                            self.updateUserProjDBPencil(completion: { (complete) in
                                print("Tony hit end 1 info artist artist db send the artist id is \(self.idG)")

                                self.dispatchGroup.leave()
                            })
                        }else if self.statusToSet == "Book" {

                            self.updateUserProjDBBook(completion: { (complete) in
                                print("Tony got to end book artist")

                                self.dispatchGroup.leave()
                            })
                        }
                    })
                })
            })
        })
    }

    self.dispatchGroup.notify(queue: DispatchQueue.main, execute: {
        print("Tony got to end all artist")
        completion(true)
    })
}
...