As far as I know, this should work this way. Are you sure your success block is called before you check the contents of allCategories ?
The success block works asynchronously, which means that it will only be executed when RequestOperation completed (which can take a long time if you download something big)
If you try to get the value of allCategories before the success block is executed, you will not get what you expect. I would recommend using breakpoints or NSLog in your success block to make sure that it was executed when you think it does.
eg
... successBlock:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"Success"); [self.allCategories addObject:tempObject] }]; //End of request [operation start]; //Begin executing the AFHTTPOperation NSLog("%@",self.allCategories.description); //probably nil or empty //since the success block hasn't been called yet
EDIT:
Be that as it may, you are returning the value before it was set using the async operation, in order to return the value from the async operation, I would suggest taking a look at this answer and this . You should also read a little about how an asynchronous task works.
Basically, what you want to do with asynchronous operations / tasks, make sure the value will be available if you want to use it. The main problem is that you do not know when the value will be set, but you can make sure that you want to do when it is set.
To do this, you can create a simple method with a custom completion block.
- (void)myCustomMethodWithCompletionBlock: (void (^)(NSArray *))completion {
Meanwhile, in the main method, you call
[self myCustomMethodWithCompletionBlock:^(NSArray *allCategories) { self.allCategories = allCategories;