Q:

need to understand objective c code for search bar

I was going through the following tutorial enter link description here 
and came across this code which stumped me on how it works:
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{

    // find all the words wich begin with the letter:

    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF beginswith[c] %@", searchText];
    //    NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:@"contains[c] %@", searchText];
    self.searchResults = [self.array filteredArrayUsingPredicate:predicate];
}

-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString

  // update the tableview 

{

    [self filterContentForSearchText:searchString

        scope:[[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:[self.searchDisplayController.searchBar

                                                     selectedScopeButtonIndex]]];

    return YES;

}

the part which I do not understand is:
 scope:[[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:[self.searchDisplayController.searchBar selectedScopeButtonIndex]]];

Here is what I understand, I tried to study it, and I know that scope a parameter. But i need just some explanation on now this works.

A:

That's a compound statement. Writing it that way makes it harder to understand.
I tend to use simpler statements and temporary variables in order to make code easier to follow. (It also makes debugging easier because you can set breakpoints between the intermediate steps and examine those temporary variables.) 
The original:
[self 
  filterContentForSearchText:searchString
  scope:[[self.searchDisplayController.searchBar scopeButtonTitles]
  objectAtIndex:
    [self.searchDisplayController.searchBar selectedScopeButtonIndex]]];

Can be broken down like this:
//Get the search bar's array of button titles
NSArray *titlesArray = 
  [self.searchDisplayController.searchBar scopeButtonTitles];

//Get the index of the selected scope button
NSInteger index = 
  [self.searchDisplayController.searchBar selectedScopeButtonIndex];

//Fetch the string at that index.

NSString *scopeString = titlesArray[index];

//Now assign the string.
[self 
  filterContentForSearchText: searchString
  scope: scopeString];

See if you can translate that into Swift. If not post back with questions.
(I'm not familiar with several of the functions used in the original code. I'm making some assumptions about what's going on based on simply parsing the Objective-C code you posted.)

