ios - Parse query finds two objects when there is only one -


i have following code find objects in custom class. reason finding 2 of same object (self.addedarray2's count 2, on parse data table online, there one). see why finding same object twice?

self.array2 = [[nsmutablearray alloc] init];     self.addedarray2 = [[nsmutablearray alloc] init];      pfquery *query = [pfquery querywithclassname:@"friends"];     [query wherekey:@"user" containsstring:[[pfuser currentuser] objectforkey:@"username"]];     [query findobjectsinbackgroundwithblock:^(nsarray *objects, nserror *error) {         (friends *currentfriend in objects) {             self.relation = currentfriend.friendsrelation;             self.addedrelation = currentfriend.addedrelation;             self.query = [_relation query];              [[_relation query] findobjectsinbackgroundwithblock:^(nsarray *objects, nserror *error) {                 [self.array2 addobjectsfromarray:objects];                  [[_addedrelation query] findobjectsinbackgroundwithblock:^(nsarray *objects, nserror *error) {                     [self.addedarray2 addobjectsfromarray:objects];                      [self.segmentcontrol settitle:[nsstring stringwithformat:@"friends (%lu)", (unsigned long)[self.array2 count]] forsegmentatindex:0];                     [self.segmentcontrol settitle:[nsstring stringwithformat:@"added me (%lu)", (unsigned long)[self.addedarray2 count]] forsegmentatindex:1];                     nslog(@"number 1: %@", [self.addedarray2 objectatindex:0]);                     nslog(@"number 2: %@", [self.addedarray2 objectatindex:1]);                  }];             }];         }     }]; 

it logging "number 1" "number 1" "number 2". looks code being run twice , adding again. how fix that? nesting, don't see can do.

for key "user" of friends class, if string holds user's username, try replacing:

[query wherekey:@"user" containsstring:[[pfuser currentuser] objectforkey:@"username"]]; 

with , let me know if changes anything:

[query wherekey:@"user" equalto:[[pfuser currentuser] objectforkey:@"username"]]; 

if pointer user object, however, want query resemble along these lines:

[query wherekey:@"user" equalto:[user currentuser]]; 

if either of assumptions wrong, let me know because not know structure of classes, try , figure out.


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -