Thread Sanitizer不会显示所有问题。例如
private func observeConversationUsers(_ isObserve: Bool, conversationID: String, updated: (() -> Void)?, fail: ((_ error: Error) -> Void)?) {
guard isObserveConversationUsers != isObserve else { return }
isObserveConversationUsers = isObserve
DispatchQueue.global(qos: .background).async {
let conversationUserRef = Database.database().reference().child(MainGateways.chat.description).child(MainGateways.conversationUsers.description).child(conversationID)
if !isObserve {
conversationUserRef.removeAllObservers()
return
}
if !self.references.contains(conversationUserRef) { // for example this issue
self.references.append(conversationUserRef)
}
conversationUserRef.observe(.childAdded, with: { (snap) in
if snap.value is NSNull {
return
}
guard let dict = snap.value as? [String : Any] else { return }
guard let chatUserActivityModel = Mapper<ChatUserActivityModel>().map(JSON: dict) else { return }
self.downloadImageProfile(chatUserActivityModel.userID, conversationID: conversationID)
}, withCancel: { (error) in
// TODO: - it
})
conversationUserRef.observe(.childRemoved, with: { (snap) in
}, withCancel: { (error) in
// TODO: - it
})
}
}
我该如何解决?
更新:我做了一个非常简单的例子,但是Xcode在这里没有显示错误,尽管在另一个线程中调用了isPushSettingsFormVC属性
class MainTabBarController: UITabBarController {
var isPushSettingsFormVC = false
override func viewDidLoad() {
super.viewDidLoad()
// I think here is a data race
DispatchQueue.global(qos: .background).async { [weak self] in
self?.isPushSettingsFormVC = false
}
}
}