I am trying to retrieve values from Firebase and then perform operations on them. However, it seems like those values are only staying assigned inside of the function call. My code looks like this:
self.ref = [[FIRDatabase database] reference];
[[_ref child:@"user"] observeSingleEventOfType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot * _Nonnull snapshot) {
// Get all user wishlists
self.wishLists = [[NSMutableDictionary alloc] initWithDictionary:snapshot.value[@"wishlist"]];
NSLog(@"%@", self.wishLists);
} withCancelBlock:^(NSError * _Nonnull error) {
NSLog(@"%@", error.localizedDescription);
}];
NSLog(@"%@", self.wishLists);
for(id key in self.wishLists){
wishList *newList = [wishList new];
newList.name = key;
NSLog(@"%@", newList.name);
[self.listArray addObject:newList];
}
where self.wishLists is defined as follows:
@property (strong) NSMutableDictionary *wishLists;
The first NSLog call to print wishList successfully prints out the value, but the second one does not, indicating that somehow self.wishLists is null even though I assigned it to the value that I pulled from Firebase. How can I keep that value assigned outside the function?