I'd like to have an array appended with values from database in viewDidLoad() so that I can extract a value and assign it to an UILabel.text after loading the view.
The codes:
var tagArr = [Tag]()
override func viewDidLoad() {
super.viewDidLoad()
let AA = fetchTagPool()
print(AA)
}
func fetchTagPool() -> [Tag]{
API.Tag.observeTagPool {(tag) in
self.tagArr.append(tag)
print(self.tagArr)
}
return self.tagArr
}
The result of print(AA)
is an empty array as []
while that of print(self.tagArr)
is the expected array appended with value from database.
How do I fix the code to make print(AA)
work as print(self.tagArr)
does?
Many thanks