Note that there are some explanatory texts on larger screens.

plurals
  1. POindex 0 beyond bounds for empty array - Found array but how to fix?
    primarykey
    data
    text
    <p>It appears my code runs fine, but if no Twitter Accounts are stored in the device, the app will crash with this error Terminating app due to uncaught exception 'NSRangeException', reason: '<em>*</em> -[__NSArrayI objectAtIndex:]: index 0 beyond bounds for empty array'</p> <pre><code>- (void)viewDidLoad { ACAccountStore *accountStore = [[ACAccountStore alloc] init]; if (accountStore != nil) { ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter]; if (accountType != nil) { [accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error) { if (granted) { NSArray *twitterAccounts = [accountStore accountsWithAccountType:accountType]; if (twitterAccounts != nil) { ACAccount *currentAccount = [twitterAccounts objectAtIndex:0]; if (currentAccount != nil) { NSString *friendListString = @"https://api.twitter.com/1.1/friends/list.json?cursor=-1&amp;skip_status=true&amp;include_user_entities=false"; SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:[NSURL URLWithString:friendListString] parameters:nil]; if (request != nil) { // 1.1 api requires a user to be logged in. [request setAccount:currentAccount]; [request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) { NSInteger responseCode = [urlResponse statusCode]; if (responseCode == 200) { // ADD STUFFS HERE } [theCollectionView reloadData]; } } }]; } } } } else { NSLog(@"User did not grant access."); } }]; } } [super viewDidLoad]; } </code></pre> <p>I'm not sure why, as I do have the nil check as seen above once it's created? <code>ACAccount *currentAccount = [twitterAccounts objectAtIndex:0];</code> How would I display an <code>UIAlertView</code> or something similar if no accounts are found on device, rather then having it crash?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload