Im trying to retrieve all the rows from a Parse server table that contains strings and images. Each one of those will then be mapped to a swift array and then used within the application. When I run this code, my append to array updates the count within the scope of the query block but once outside this block of code - I have an empty array as was initialized.
var langArray = [String]()
override func viewDidLoad() {
super.viewDidLoad()
let query = PFQuery(className:"Languages")
query.findObjectsInBackground { (objects, error) -> Void in
if error == nil {
for object in objects! {
self.langArray.append(object["name"] as! String)
print("inside this loop: \(self.langArray.count)")
}
} else {
print(error!)
}
print("outside the foreach loop: \(langArray.count)")
}
As per the code, Im running the query in the viewDidLoad() so it would be the first thing being retrieved.