title: Loading Data and Appending without Repetition
body: <p>I am currently trying to sort the PFObjects I receive from Parse.com and differentiate them between 'near' and 'far'. So far I am able to place these objects in tuples </p>
  
  <p>var placesID = [(Name: "PlaceName"), (Distance: Double)] </p>
  
  <p>The issue that I am having is the process of differentiating these objects (based on distance) and appending them into separate arrays (nearArray &amp; farArray). </p>
  
  <p>The main problem that I am dealing with is the fact that the tuples are loaded from Parse one at a time. Thereby, the first iteration would be </p>
  
  <p>[(Name: Place A, Distance: 10)]</p>
  
  <p>followed by </p>
  
  <p>[(Name: Place A, Distance: 10), (Name: Place B, Distance: 20)] </p>
  
  <p>and so forth depending on the number of places I have stored in Parse. </p>
  
  <p>Since there are multiple iterations my current method of differentiation the objects through-</p>
  
  <pre><code>    for x in self.PlacesID {
                     if x.Distance &lt; 15 {
                     self.nearPlacesID.append(x)       
                      }
                             } 
  </code></pre>
  
  <p>does not work as the object with name "Place A" gets iterated multiple times and is able to satisfy the distance constraint. Therefore, the "Place A" gets appended multiple times in the nearPlacesID tuple. I was wondering if there is anyway to have the method wait until all the PFObjects are loaded before it does the differentiates all the objects based on distance. Or if there is any other way to solve the issue, I would greatly appreciate it. </p>
  
  <p>This is the code I have at the moment. </p>
  
  <pre><code>var placesID: [(Name: String?, Distance: Double?, Image: UIImage?)] = []
  
  var nearplacelID: [(Name: String?, Distance: Double?, Image: UIImage?)] = []
  
  var farplaceID: [(Name: String?, Distance: Double?, Image: UIImage?)] = []
  
  
  override func viewDidLoad() {
  
      super.viewDidLoad()
      var query = PFQuery(className: "VenueData")
  
      dispatch_async(dispatch_get_global_queue(Int(QOS_CLASS_USER_INTERACTIVE.value), 0)){
  
  
      let object = query.findObjects() //Get the Object
  
  
  
      PFGeoPoint.geoPointForCurrentLocationInBackground({ (userLocation: PFGeoPoint?, error: NSError?) -&gt; Void in //Get User Location
          if let myObject = object as? [PFObject] {
  
  
  
  
              for x in myObject {
                  var name = x.objectForKey("Name") as? String
  
                  var location = x.objectForKey("Location") as? PFGeoPoint
                  var distance = location?.distanceInKilometersTo(userLocation)
  
                  var File: PFFile? = x.objectForKey("ImageFile") as? PFFile
                  File?.getDataInBackgroundWithBlock({ (imagedata: NSData?, error: NSError?) -&gt; Void in
                       var image = UIImage(data:imagedata!)
  
  
                  self.placesID += [(Name:name, Distance: distance, Image: image)]
  
                      self.tableView.reloadData()
  
                      for x in self.placesID {
                          if x.Distance &lt; 1 {
                           self.nearplaceID.append(x)
                           }
                      }
  
  
                      for x in self.placesID {
                          if x.Distance &gt; 1 &amp;&amp; x.Distance &lt; 10 {
                              self.farplaceID.append(x)
                          }
                      }
  
  
                  })
  
              }
  
  
      }
  
  
      })
  
  
      }
     }
  </code></pre>