-[__NSCFDictionary objectAtIndexedSubscript:]: unrecognized selector sent to instance
ios, objective-c, uitableview
Solution
The problem is that `_array` is not an array (it's a dictionary).
You only have to read the error message to see this.
You can't make any assumptions about what kind of object `JSONObjectWithData:options:error:` will give you; it depends on what the JSON data looks like. In this case, the JSON structure has resulted in the Objective-C equivalent being an NSDictionary. The fact that you may have called your `array` instance variable an NSArray makes no difference; in Objective-C, an object is what it is (polymorphism).
You didn't catch the problem earlier because `count` is a method both of NSDictionary and of NSArray, so you didn't crash when you said `self.array.count`.
Problem
I used one tutorial to include My twitter home page in my code, but for me does not works. This is the code ``` @implementation VSViewController - (void)viewDidLoad { [super viewDidLoad]; [self twitterTimeline]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)twitterTimeline { ACAccountStore *account = [[ACAccountStore alloc] init]; // Creates AccountStore object. // Asks for the Twitter accounts configured on the device. ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter]; [account requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error) { // If we have access to the Twitter accounts configured on the device we will contact the Twitter API. if (granted == YES){ NSArray *arrayOfAccounts = [account accountsWithAccountType:accountType]; // Retrieves an array of Twitter accounts configured on the device. // If there is a leat one account we will contact the Twitter API. if ([arrayOfAccounts count] > 0) { ACAccount *twitterAccount = [arrayOfAccounts lastObject]; // Sets the last account on the device to the twitterAccount variable. NSURL *requestAPI = [NSURL URLWithString:@"http://api.twitter.com/1.1/statuses/user_timeline.json"]; // API call that returns entires in a user's timeline. // The requestAPI requires us to tell it how much data to return so we use a NSDictionary to set the 'count'. NSMutableDictionary *parameters = [[NSMutableDictionary alloc] init]; [parameters setObject:@"100" forKey:@"count"]; [parameters setObject:@"1" forKey:@"include_entities"]; // This is where we are getting the data using SLRequest. SLRequest *posts = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:requestAPI parameters:parameters]; posts.account = twitterAccount; // The postRequest: method call now accesses the NSData object returned. [posts performRequestWithHandler: ^(NSData *response, NSHTTPURLResponse *urlResponse, NSError *error) { // The NSJSONSerialization class is then used to parse the data returned and assign it to our array. self.array = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error]; if (self.array.count != 0) { dispatch_async(dispatch_get_main_queue(), ^{ [self.tableView reloadData]; // Here we tell the table view to reload the data it just recieved. }); } }]; } } else { // Handle failure to get account access NSLog(@"%@", [error localizedDescription]); } }]; } #pragma mark Table View Data Source Mehtods -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { // Returns the number of rows for the table view using the array instance variable. return [_array count]; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { // Creates each cell for the table view. static NSString *cellID = @"CELLID" ; UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:cellID]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID]; } // Creates an NSDictionary that holds the user's posts and then loads the data into each cell of the table view. ``` IT CRASHES HERE with the error -[__NSCFDictionary objectAtIndexedSubscript:]: unrecognized selector sent to instance ``` NSDictionary *tweet = _array[indexPath.row]; cell.textLabel.text = tweet[@"text"]; return cell; } ```