Reputation: 183
I wonder if my code fetches an array in parse.com and adds it correctly to my NSMutableArray.
In ViewdidLoad:
self.alreadySharedWith = [NSMutableArray array];
//detailId contains the current posts objectId.
PFQuery *currentPostSharedWith = [PFQuery queryWithClassName:@"Posts"];
[currentPostSharedWith getObjectInBackgroundWithId:detailId block:^(PFObject *object, NSError *error) {
self.alreadySharedWith = [NSMutableArray arrayWithObjects:object[@"sharedWithUsers"], nil];
NSLog(@"These are already shared: %@", self.alreadySharedWith);
}];
What this does is: Gets all user's objectId where the current user's post has been shared with. (Current user can share a post with other users)
MY NSLog displays this:
These are already shared: ( ( Vf5zOl2DiR, LMiQK016A5, 2O906caJgJ ) )
But when i try check whether or not Vf5zOl2DiR exists in my alreadySharedWith, i get no result. why is that so?
How i check the array for a object.
- (void)checkArray:(id)sender{
if ([self.alreadySharedWith containsObject:@"Vf5zOl2DiR"]) {
NSLog(@"Found it!");
}
}
My log doesn't display anything.
Upvotes: 0
Views: 72
Reputation: 9913
It looks like you're putting an array inside an array when you populate self.alreadySharedWith
. Maybe try changing (in viewDidLoad
)
self.alreadySharedWith = [NSMutableArray arrayWithObjects:object[@"sharedWithUsers"], nil];
to
self.alreadySharedWith = (NSMutableArray *)object[@"sharedWithUsers"];
Upvotes: 1