0
viewDidLoad
の関数を使用して配列を追加し、その配列を他の関数で使用しています。私のプログラムを実行すると、の関数は完全に実行されません。私はこれを手伝ってください。Swift 3 - viewdidloadの関数が完全に実行されていない
私のコード: -
override func viewDidLoad() {
super.viewDidLoad()
self.getAllUsers()
self.fetchData()
}
func getAllUsers(){
ref = Database.database().reference()
ref.child("users").observe(.value, with: { (snapshot) in
if let result = snapshot.children.allObjects as? [DataSnapshot] {
for child in result {
var userid = child.key
print(userid)
self.uuid.append(userid)
}
}
if self.uuid.contains((Auth.auth().currentUser?.uid)!) {
print("Id matched")
}
})
let array = ["Frodo", "sam", "wise", "gamgee"]
let randomIndex = Int(arc4random_uniform(UInt32(array.count)))
print(array[randomIndex])
}
func fetchData() {
let randomIndex = Int(arc4random_uniform(UInt32(uuid.count)))
print(uuid[randomIndex])
print(randomIndex)
randomI = randomIndex
Message.downloadAllMessages(forUserID: uuid[randomIndex], completion: {[weak weakSelf = self] (message) in
weakSelf?.items.append(message)
weakSelf?.items.sort{ $0.timestamp < $1.timestamp }
DispatchQueue.main.async {
if let state = weakSelf?.items.isEmpty, state == false {
weakSelf?.tableView.reloadData()
weakSelf?.tableView.scrollToRow(at: IndexPath.init(row: self.items.count - 1, section: 0), at: .bottom, animated: false)
}
}
})
Message.markMessagesRead(forUserID: uuid[randomIndex])
}
あなたが試したことを示してください。 –
はviewDidLoad()オペレーションを示します。 –
フルコードを表示できますか? –