For some reason I can't get twitterAccounts to hold another arrays data.
ViewController.h
@interface ViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
@property (strong, nonatomic) NSArray *twitterAccounts;
@property (strong, nonatomic) IBOutlet UITableView *chooseTwitterAccountTableView;
- (void)twitterRequest;
@end
ViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
_twitterAccounts = [[NSArray alloc]init];
[self twitterRequest];
}
- (void)twitterRequest {
ACAccountStore *account = [[ACAccountStore alloc]init];
ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[account requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error) {
if (granted == YES) {
NSArray *twitterAccountsTemp = [account accountsWithAccountType:accountType];
_twitterAccounts = twitterAccountsTemp;
NSLog(@"Array first has: %lu elements.", [_twitterAccounts count]);
}
}];
}
What I don't understand is if I have my viewDidLoad method like this:
- (void)viewDidLoad
{
[super viewDidLoad];
_twitterAccounts = [[NSArray alloc]init];
[self twitterRequest];
NSLog(@"After method called: %lu", [_twitterAccounts count]);
}
The output is:
After method called 0.
Array first has: 1 elements.
is it not supposed to be the other way around since I'm calling the method before outputting the amount of elements in the array?