Advertisement
Guest User

Untitled

a guest
Jul 29th, 2015
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. class DriverViewController: UIViewController {
  2. var placesArr : Array<Place> = []
  3.  
  4.  
  5. override func viewDidLoad() {
  6. super.viewDidLoad()
  7. self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
  8.  
  9.  
  10. var query = PFQuery(className:"places")
  11. query.whereKey("username", equalTo:"email@email.com")
  12. query.findObjectsInBackgroundWithBlock {
  13. (objects: [AnyObject]?, error: NSError?) -> Void in
  14.  
  15. if error == nil {
  16. println("Successfully retrieved (objects!.count) scores.")
  17.  
  18. if let objects = objects as? [PFObject] {
  19. for object in objects {
  20. let x = Place(aIdent: (object["Ident"] as! Int), aName: (object["name"] as! String), aAddress: (object["originAddress"] as! String), aCity: (object["originCity"] as! String), aCategoryName: (object["catName"] as! String), aLat: (object["aLat"] as! String), aLng: (object["aLng"] as! String))
  21.  
  22. self.placesArr.append(x)
  23. println(placesArr) //****It works here and prints an array****
  24. }
  25. }
  26. } else {
  27. // Log details of the failure
  28. println("Error: (error!) (error!.userInfo!)")
  29. }
  30. }
  31. println(placesArr) //****But here it returns a blank array and this is where I need it to return an array****
  32.  
  33. // Runs 1st
  34. query.findObjectsInBackgroundWithBlock {
  35. (objects: [AnyObject]?, error: NSError?) -> Void in
  36. // Runs 3rd
  37. }
  38. // Runs 2nd
  39. println(placesArr)
  40.  
  41. var placesArray: [Place] = [] {
  42. didSet {
  43. // Do any execution that needs to wait for places array here.
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement