title: Parse retrieve objectId from class causes app to stop (not crash)
body: <p>I have already submitted a question on how to retrieve an objectId (<a href="https://stackoverflow.com/questions/28621309/swift-retrieve-objectid-field-causes-fatal-error">swift - retrieve objectId field causes fatal error</a>) but that seems to only apply to objects during a save because I have spent a long time (days) trying to retrieve the objectId from a saved row in a Parse cloud DB with absolutely no luck.  I've mimicked the code in the Parse object retrieval documentation (<a href="https://parse.com/docs/ios_guide#objects-retrieving/iOS" rel="nofollow noreferrer">https://parse.com/docs/ios_guide#objects-retrieving/iOS</a>), using the special values provided for objectId's:</p>
  
  <pre><code>let objectId = gameScore.objectId
  </code></pre>
  
  <p>I was getting a crash every time but now the app just stops after printing the successful login message.  Here is the code and sequence of events.</p>
  
  <p>I signup a new user (let's call him vin).  </p>
  
  <p>The signup code: </p>
  
  <pre><code>@IBAction func signUp(sender: AnyObject) {
      if countElements(self.userNameTextField.text) &gt; 0 &amp;&amp; countElements(self.passWordTextField.text) &gt; 0 {
      var megabyker = PFUser()
      user.username = self.userNameTextField.text
      user.password = self.passWordTextField.text
              user.signUpInBackgroundWithBlock{
                  (succeeded:Bool!, error:NSError!)-&gt;Void in
                    if error == nil {
                      println("Sign Up successfull")
  
                      //associate current user for parse remote push notifications
                      var installation:PFInstallation = PFInstallation.currentInstallation()
                      installation.addUniqueObject("goride", forKey: "channels")
                      installation["user"] = PFUser.currentUser()
                      installation.saveInBackground()
  
                      //default row for allData table
                      //save default settings row for GUEST user
                      var alldata:PFObject = PFObject(className: "allData")
                      alldata["divvy_routes"] = "ON"
                      alldata["sortBy"] = "distance"
                      alldata["totalRides"] = 0
                      alldata["username"] = user.username
                      //self.useGuestUser = "USER"
                      alldata["user"] = PFUser.currentUser()
                      alldata.saveInBackgroundWithBlock{(success:Bool!, error:NSError!) -&gt;Void in
                          if success != nil {
                              NSLog("%@","OK-alldata REAL data saved")
                              self.allDataSignUpObjectId = alldata.objectId
                              println("printing out objectId var in ALLDATA REAL section: ")
                              println(self.allDataSignUpObjectId)
                              self.performSegueWithIdentifier("go-to-main-menu", sender: self)
                          }
                          else
                          {
                              NSLog("%@",error)
                          }
                      }
                    } else {
                      let alert = UIAlertView()
                      alert.title = "Invalid Signup"
                      alert.message = "Sorry, a username (unique) and a password are required to create a new account."
                      alert.addButtonWithTitle("OK")
                      alert.show()
                  }
          }
      }
      else
      {
          let alert = UIAlertView()
          alert.title = "Invalid Signup"
          alert.message = "Sorry, a username (unique) and a password are required to create a new account."
          alert.addButtonWithTitle("OK")
          alert.show()
      }
  }
  </code></pre>
  
  <p>The signup code works fine.  It creates a new user and row in the User table and new default row in the allData table.  The allData table has a user pointer column to associate it with the User table.  I grab the objectId and assign it to an instance variable because I want to pass it to another viewcontroller to use:</p>
  
  <pre><code>self.allDataSignUpObjectId = alldata.objectId
  println(self.allDataSignUpObjectId)
  </code></pre>
  
  <p>And here is a screenshot of the ParseDB where you can see the row has been saved in the user table for the new user.  His objectId is 9vRF8BvdlZ and the row in the allData table has an objectId of DEaj0iWZ3X.  This is the objectId I am trying to get (DEaj0iWZ3X).</p>
  
  <p>allData table:</p>
  
  <p><img src="https://i.stack.imgur.com/pTSvO.png" alt="enter image description here"></p>
  
  <p>Now here is the allData where the new user's default setting row is inserted and it's automatically linked to the Vin's user table:</p>
  
  <p><img src="https://i.stack.imgur.com/qHXhL.png" alt="enter image description here"></p>
  
  <p>I then go to the Settings view controller and Save as the newly created user:</p>
  
  <pre><code>    @IBAction func updateSettings(sender: AnyObject) {
  
      var alldata:PFObject = PFObject(className:"allData")
  
      var user = PFUser.currentUser()
      var query = PFQuery(className:"allData")
      query.whereKey("user", equalTo: user)
      var id = allDataPass
  
      println(id)
  
      query.getObjectInBackgroundWithId(id) {
          (alldata: PFObject!, error: NSError!) -&gt; Void in
          if error != nil {
              NSLog("%@", error)
          } else {
              alldata["routes"] = self.RoutesSetting
              alldata.saveInBackground()
          }
      }
  }
  </code></pre>
  
  <p>It saves with no problems and the updated time in the row updates. </p>
  
  <p>But when I logback in as Vin (after resetting the contents and settings on the simulator to get a fresh start), I get to LOGIN but it just stops (not crash, just stops and won't get past the login screen).</p>
  
  <p>Here's the console printout:</p>
  
  <pre><code>2015-02-26 22:19:01.732 MegaByke[51906:6996084] Location Services Not Determined, must ask user
  2015-02-26 22:19:01.734 MegaByke[51906:6996084] location services enabled: true
  Location services success - &lt;MegaByke.AppDelegate: 0x7ff4b145bd80&gt;
  2015-02-26 22:19:15.700 MegaByke[51906:6996084] Reachability Flag Status: -R -----l- networkStatusForFlags
  &lt;PFUser: 0x7ff4b167f830, objectId: 9vRF8BvdlZ, localId: (null)&gt; {
  username = vin;
  }
  Login successfull
  objectId preFETCH 
  nil
  </code></pre>
  
  <p>Here is my login code:</p>
  
  <pre><code>        @IBAction func login(sender: AnyObject) {
  
      switch reachability!.currentReachabilityStatus().value{
      case NotReachable.value:
          var alert = UIAlertView(title: "No Internet Connection", message: "In order to login, you must have internet connection. You can still login as a Guest", delegate: nil, cancelButtonTitle: "Dismiss")
          alert.show()
      default:
          if countElements(self.userNameTextField.text) &gt; 0 &amp;&amp; countElements(self.passWordTextField.text) &gt; 0 {
              PFUser.logInWithUsernameInBackground(userNameTextField.text, password: passWordTextField.text){
                  (user:PFUser!, error:NSError!)-&gt;Void in
                  if user != nil
                  {
                      println(user)
                      println("Login successfull")
  
                      //associate current user for parse remote push notifications
                      var installation:PFInstallation = PFInstallation.currentInstallation()
                      installation.addUniqueObject("goride", forKey: "channels")
                      installation["user"] = PFUser.currentUser()
                      installation.saveInBackground()
  
                      var user = PFUser.currentUser()
                      var query = PFQuery(className:"allData")
                      query.whereKey("user", equalTo: user)
  
                      // Retrieve the most recent one
                      query.orderByDescending("createdAt")
                      query.limit = 1;
  
                      //assign objectId
                      var alldata = PFObject(className:"allData")
                      println("objectId preFETCH")
                      println(alldata.objectId)
  
                      //refresh object
                      alldata.fetch()
                      let id = alldata.objectId
                      println("objectId postFETCH")
                      println(id)
  
                      query.getObjectInBackgroundWithId(id) {
                          (alldata: PFObject!, error: NSError!) -&gt; Void in
                          if error == nil {
                              //Load parse data from cloud
                              NSLog("%@", alldata)
                              self.performSegueWithIdentifier("go-to-main-menu", sender: self)
                          } else {
                              NSLog("%@", error)
                          }
                      }
                  }
                  else { // Log details of the failure
                      NSLog("Error: %@ %@", error, error.userInfo!)
                  }
              }
          }
          else{
              println(user)
              let alert = UIAlertView()
              alert.title = "Invalid Login"
              alert.message = "Sorry, that username and/or password is incorrect.  Please enter a valid combination."
              alert.addButtonWithTitle("OK")
              alert.show()
              println("Login failed")
          }
      }
  }
  </code></pre>
  
  <p>The println that's supposed to occur after the fetch never gets to the console so I'm assuming I have not successfully retrieved the objectId.  I have also checked Parse's user forum and no help there.  </p>