I don’t understand what the line [nextCard.name caseInsensitiveCompare:theName] == **NSOrderedSame** of the instance method [nextCard.name caseInsensitiveCompare:theName] == **NSOrderedSame** .

What should nextCard.name caseInsensitiveCompare:theName ?

I would be grateful for chewing the mechanics of this piece.

The method itself:

 -(AddressCard *) lookup: (NSString *) theName { for (AddressCard *nextCard in book) { if ([nextCard.name caseInsensitiveCompare:theName] == NSOrderedSame) return nextCard; } return nil; } 

    1 answer 1

    This method checks strings for equality, while not paying attention to whether words with capital letters are written or not. For example, @"One more THING" and @"one more thing" will be identical strings. This method does not just return the value YES or NO, but what exactly it returns you can see for yourself. Specifically, your method does what, going over an array of elements, compares the name field with the input parameter of the function, and if they match, it returns this object, if not, it simply returns nil . Only one thing is not clear where the book array is declared.

    • Ilya, thanks for the answer! The book array was declared earlier and everything is fine with it :) But, I did not quite correctly express my question. The for loop sequentially compares the elements of the array with the theName variable in [nextCard.name caseInsensitiveCompare: theName], but I don’t understand further, the equal sign and "NSOrderedSame" which should correspond to? Why do we write "== NSOrderedSame"? - Dubplate
    • @Dubplate is just such a comparison of the return value of a function with nsorderedsame, the double equality sign is a comparison. You swim a lot in basic terms, see the book the power of objective-c or other books on the basics of objective-c. - Ilya Tereznikov
    • I agree, I am reading now the book Objective-C by Stephen Kochan, this example from there. - Dubplate
    • All figured out. Maybe a little clumsy, I will explain for newcomers like me. "NSOrderedSame" is a phrase that says that two objects are equal. Those. The caseInsensitiveCompare method returns "NSOrderedSame" if nextCard.name and "theName" match, and the equality (== NSOrderedSame) is satisfied "and the if construct is executed. - Dubplate
    • @Dubplate yes that's right) move in the same direction)) - Ilya Tereznikov