コードがスレッドセーフであるかどうかは、tableView(_ tableView :, leadingSwipeActionsConfigurationForRowAt indexPath :)です。フレンドリクエストを受け付けるアクションを作成します。FirebaseにiOSを書き込むとクラッシュする
class func acceptInvite(uid: String, completion: @escaping (Bool)->Void) {
guard let user = currentUser else { completion(false); return }
usersRef.child(user.uid).child("invites").queryEqual(toValue: uid).ref.removeValue()
usersRef.child(user.uid).child("friends").childByAutoId().setValue(uid)
usersRef.child(uid).child("friends").childByAutoId().setValue(user.uid)
completion(true)
}
:実際Firebase呼び出しは次のようである
{に(アクション、ビュー、ハンドラ)}メソッドはUIContextualAction(NIL:.normal、タイトルスタイル)のBLOKから呼び出されます
誰か説明があればうれしいです。
編集:私はこの問題は、ユーザデータ
class func get(type: String, completion: @escaping ([Friend])->Void) {
let usersRef = Database.database().reference().child("users")
guard let user = currentUser else { completion([]); return }
usersRef.child(user.uid).child(type).observe(.value){ (snapshot) in
guard let invitesKeyValues = snapshot.value as? [String: String] else { completion([]); return }
var optionalFriendsDictArray: [[String: Any]?] = []
let dispatchGroup = DispatchGroup()
for (_, inviteUID) in invitesKeyValues {
dispatchGroup.enter()
usersRef.child(inviteUID).observe(.value, with: { (snapshot) in
let friend = snapshot.value as? [String: Any]
optionalFriendsDictArray.append(friend)
dispatchGroup.leave()
})
}
dispatchGroup.notify(queue: DispatchQueue.global(), execute: {
let friends = optionalFriendsDictArray.flatMap({ (optional) -> Friend? in
Friend.init(userDictionary: optional)
})
completion(friends)
})
}
}
この問題は本当にFirebase使い方について考えて私を取得を取得するために私の非同期ループであると思います。ユーザーのフレンドキーにユーザーに関する情報を追加して、名前と写真付きの小さなリストを作成するためにすべてのユーザーを照会する必要はありません。 しかし、あなたのタイムライン上であなたの友人の投稿を見ることはどうでしょうか、すべての友人の投稿をユーザーオブジェクトにコピーすることは間違いありません。 ???
これはユーザーのオブザーバーと関係があります。観察者は、観察されているユーザーに書きたいときにクラッシュの原因と思われる。 –
クラッシュログの詳細を共有できますか? –
ログに何もありません。デバッグナビゲータを見てスレッドの問題だと思います –