0

I am trying to download an array from Back4Apps.com (Parse.com equivalent). The below displays no errors, but when it gets to the line "downloadQuery.findObjectsInBackground { (objects, error) in", it simply skips over the rest of the code to the end of the function.

  • I have tested the "username" and it seems to be correct.
  • I am certain the class and subClass names are correct.
  • The parse parameters are correct and I already have many other parse functions working.

Any suggestions where to look?

var userCommonNameArray = [String]()
var userCommonNameESArray = [String]()
var userCommonNameFRArray = [String]()
var userCommonNameDEArray = [String]()
var speciesNameArray = [String]()
var userNotesArray = [String]()


    func insertFromParse () {

        let username = userDefault.value(forKey: "username") as! String

        let downloadQuery = PFQuery(className:"ReefLifeApps")
        downloadQuery.whereKey("username", equalTo: username)



//    This is there Xcode skips from to the end
//    tried variations of the below line.  Neither worked.            
//      downloadQuery.findObjectsInBackground {(objects, error) -> Void in
        downloadQuery.findObjectsInBackground { (objects, error) in

            if error == nil {
                // Do something with the found objects
                for object in objects! {

                    self.userCommonNameArray.append(object.object(forKey: "userCommonName") as! String)
                    self.userCommonNameESArray.append(object.object(forKey: "userCommonNameES") as! String)
                    self.userCommonNameFRArray.append(object.object(forKey: "userCommonNameFR") as! String)
                    self.userCommonNameDEArray.append(object.object(forKey: "userCommonNameDE") as! String)
                    self.speciesNameArray.append(object.object(forKey: "speciesName") as! String)
                    self.userNotesArray.append(object.object(forKey: "userNotes") as! String)

                }
            } else {

                print("Error: \(error!)")
            }
        }
}
David Sanford
  • 735
  • 12
  • 26
  • when you say "it skips over", are you watching execution line by line in the debugger? the find runs async, you won't see execution enter there unless you set a breakpoint inside the block. – danh Dec 23 '16 at 17:16
  • Yes, I was watching the execution line by line in the debugger. I used the Step Into during this process and it did not reach the "if error == nil" line. Do you have any suggestions how to dig dipper? – David Sanford Dec 23 '16 at 17:57
  • sure. set a breakpoint *inside* the completion block. then resume execution at full speed. the idea is that find runs after the current run loop returns. you'll only execute the completion after a round trip on the network is done, which is much later than when the debugger runs the findObjects function. – danh Dec 23 '16 at 18:00
  • if seems you are right. The data was actually downloading, but the error was just after this function as when I tested if array.count > 0, this is what was broken. Thank you – David Sanford Dec 23 '16 at 18:32

0 Answers0