Reputation: 1527
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
I put
NSAssert([searchBar.text isEqualToString:searchText],@"Search Bar Must Be The Same");
there and it doesn't seem to be violated
I just want to make sure because it's kind of strange.
Why bother having 2 parameters, searchBar and searchText if one of the parameter, namely searchText can be gotten simply by asking searchBar.text
Why not just have
-(void)searchBarTextDidChange:(UISearchBar *) searchBar
or -(void)textDidChangeForSearchBar:(UISearchBar *) searchBar
Doing it
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
implies that searchText carries essential information which mean that searchBar.text may differ from searchText. It never is. Unless of course you change things.
In fact, I suspected that searchText either points to searchBar.text or just a copy of it.
Upvotes: 0
Views: 77
Reputation: 39988
I would say it's just a coding standard.
It's a good practice that the first argument of a delegate method should be the calling class
So (void)searchBar:(UISearchBar *)searchBar
follows that.
Now if you omit textDidChange:(NSString *)searchText
which can be retrieved from searchBar.Text
then neither I nor Apple has found a good name for this method.
Upvotes: 2
Reputation: 7102
I also checked with all the possiblity. I think the only region for providing another parameter is to make consistency in these two functions
- (BOOL)searchBar:(UISearchBar *)searchBar shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text;
And
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
Upvotes: 1