In my view controller, I've got data inside of self.acceptedFriends. In my first if statement, the mutable array populates perfectly and data is present. However, in my last portion of the statement ( else if ([neighbourDetail count] > 0) ), self.acceptedFriends is empty for some reason? Any idea why this might be?
Note: This question is different than the linked examples, as the data IS working outside of the AFNetworking block - it's populated inside the first if statement, just not the last.
ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController <UIAlertViewDelegate>
@property (nonatomic, strong) NSMutableArray *acceptedFriends;
@end
ViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
NSMutableDictionary *viewParams3 = [NSMutableDictionary new];
[viewParams3 setValue:@"accepted_friends" forKey:@"view_name"];
[DIOSView viewGet:viewParams3 success:^(AFHTTPRequestOperation *operation, id responseObject) {
self.acceptedFriends = (NSMutableArray *)responseObject;
[operation responseString];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Failure: %@", [error localizedDescription]);
}];
if ([self.mapuserData count] > 0 ) {
NSLog(@"This is map user data %@", self.mapuserData);
NSString *thisUserId = [self.mapuserData objectForKey:@"users_name"];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"node_title CONTAINS[cd] %@",
thisUserId];
NSArray *resultArray = [self.acceptedFriends filteredArrayUsingPredicate:predicate];
if (!resultArray) {
NSLog(@"Executed!");
self.addFriend.hidden = YES;
self.orangeFriendCircle.hidden = YES;
}
} else if ([self.frienduserData count] > 0) {
self.addFriend.hidden = YES;
self.orangeFriendCircle.hidden = YES;
self.username.text = self.frienduserData[@"node_title"];
self.userBio.text = self.frienduserData[@"body"];
NSString *thirdLink = self.frienduserData[@"friendphoto"];
NSString *ImageURLTwo = thirdLink;
NSData *imageDataTwo = [NSData dataWithContentsOfURL:[NSURL URLWithString:ImageURLTwo]];
self.userPhoto.image = [[UIImage alloc] initWithData:imageDataTwo];
} else if ([neighbourDetail count] > 0) {
NSString *thisUserId = [self.neighbourDetail objectForKey:@"users_name"];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"node_title CONTAINS[cd] %@",
thisUserId];
NSArray *resultArray = [self.acceptedFriends filteredArrayUsingPredicate:predicate];
if ([resultArray count] > 0) {
NSLog(@"Executed!");
self.addFriend.hidden = YES;
self.orangeFriendCircle.hidden = YES;
}
}
}