Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer 1

up vote 4 down vote accepted

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];
}
share|improve this answer
    
thanks for good answer. –  js_ Aug 28 '12 at 11:26
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.