現在、FIREBASEから全ユーザーの情報を取得しTableviewに表示しています。
そのために、このようなModelを作成しました。
import Foundation import Firebase import FirebaseDatabase struct User { var username: String! var email: String? var country: String? var photoURL: String! var ref: FIRDatabaseReference? var key: String? init(snapshot: FIRDataSnapshot){ key = snapshot.key ref = snapshot.ref username = (snapshot.value! as! NSDictionary)["username"] as! String email = (snapshot.value! as! NSDictionary)["email"] as? String country = (snapshot.value! as! NSDictionary)["country"] as? String photoURL = (snapshot.value! as! NSDictionary)["photoURL"] as! String } }
そして下記のようにデータをFetchしました。
var usersArray = [User]() func fetchUsers(){ dataBaseRef.child("users").observe(.value, with: { (snapshot) in var results = [User]() for user in snapshot.children { let user = User(snapshot: user as! FIRDataSnapshot) if user.uid != FIRAuth.auth()!.currentUser!.uid { results.append(user) } } self.usersArray = results self.tableView.reloadData() }) { (error) in print(error.localizedDescription) } }
データの取得は成功するのですが、私のしたいことはphotoURLは違うVIEWから他の要素とは別のタイミングで入力されたものを使用したいです。例えばphotoURLはVIEW1でその他はVIEW2で入力してもらう形をとり、func fetchUsers()を呼ぶ際にnodeがこのようになっていたとします。
"User": { "uid1": { "username": "some text", "email": "some text", "country": "some text", "photoUrl": "some text" }, "uid2": { "username": "some text", "email": "some text", "country": "some text", "photoUrl": "some text" }, "uid3": { "username": "some text", "email": "some text", "country": "some text", } }
この場合、uid3にphotoUrlがまだ入力されていない状態になっているのでuid3を飛ばしてuid1とuid2のみをTableviewに表示することは可能でしょうか?
可能であればどのような流れになるのかご教示いただけますとありがたいです。
よろしくお願い申し上げます。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/12/11 06:47
2017/12/11 07:12
2017/12/11 07:24
2017/12/11 08:02 編集
2017/12/11 08:53