Trouble accessing Mutable array
- by Jared Gross
Im having trouble with my for loop where I am trying to index user names. I am able to separate my original array into individual objects but am not able to send the value to a new array that I need to reference later on. The value and count for userNames in my self.userNamesArray = userNames; line is correct. But right after that when I log self.userNamesArray, I get (null). Any tips cause I'm not completely sure I'm  cheers!
.h
@property (nonatomic, copy) NSMutableArray *userNamesArray;
.m
- (void)viewWillAppear:(BOOL)animated {
self.friendsRelation = [[PFUser currentUser] objectForKey:@"friendsRelation"];
PFQuery *query = [self.friendsRelation query];
[query orderByAscending:@"username"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
    if (error) {
        NSLog(@"Error: %@ %@", error, [error userInfo]);
    }
    else {
        self.friends = objects;
        NSArray *users = [self.friends valueForKey:@"username"];
        NSLog(@"username:%@", users);
        //Create an array of name wrappers and pass to the root view controller.
        NSMutableArray *userNames = [[NSMutableArray alloc] initWithCapacity:[self.friends count]];
        for (NSString *user in users) {
        componentsSeparatedByCharactersInSet:charSet];
            NSArray *nameComponents = [user componentsSeparatedByString:@" "];
            UserNameWrapper *userNameWrapper = [[UserNameWrapper alloc]    initWithUserName:nil nameComponents:nameComponents];
            [userNames addObject:userNameWrapper];
        }
        self.userNamesArray = userNames;
        NSLog(@"userNamesArray:%@",self.userNamesArray);
        [self.tableView reloadData];
    }
Here's the code where I need to reference the self.userNamesArray where again, it is comping up nil.
- (void)setUserNamesArray:(NSMutableArray *)newDataArray {
if (newDataArray != self.userNamesArray) {
    self.userNamesArray = [newDataArray mutableCopy];
    if (self.userNamesArray == nil) {
        self.sectionsArray = nil;
        NSLog(@"user names empty");
    }
    else {
        [self configureSections];
    }
}
}