3

I have a following method to find index of a book object which have a book name:

+(NSInteger)indexXXX:(NSString *)bookName XXX:(NSArray *)books
{
  for (NSInteger i = 0; i < books.count; i++) {
    NSDictionary *book = [books objectAtIndex:i];
    if ([[book objectForKey:@"bookName"] isEqualToString:bookName]) {
      return i;
    }
  }
  return -1;
}

But I don't know what name should I use for this method.
Could you tell me some method names commonly used for this kind of method.

js_
  • 143
  • 1
  • 5

1 Answers1

4

Usually we just name methods after what they do, so something like indexOfObjectWithName: inArray: would work.

To carry on past answering this question, the method can be made much simpler:

{
    NSArray *names = [books valueForKey: @"bookName"];
    return [names indexOfObject: bookName];
}