If you're worried about performance, and you want to check for one character, using -characterAtIndex: method may well be faster. -hasSuffix: takes a string, so potentially needs to do more work than just checking a single character (though the difference may be trivial).
You can also use categories to add a method to NSString like this:
@interface NSString(StringUtilities)
- (BOOL) endsWithCharacter: (unichar) c;
@end
@implementation NSString(StringUtilities)
- (BOOL) endsWithCharacter: (unichar) c
{
NSUInteger length = [self length];
return (length > 0) && ([self characterAtIndex: length - 1] == c);
}
@end
// test it...
NSString *data = @"abcd,";
if ([data endsWithCharacter: L','])
{
}
You should profile, of course, to be sure. Bear in mind though that by putting endsWithCharacter into a method we've added the message passing overhead to it, which will skew the profiling results unless you do the same when profiling the alternatives.
All of this is probably premature optimisation for most cases - but of course if you're doing this test thousands of times a second it may well matter (in that case you would probably want to use the code directly in the loop, as message passing inside a tight inner loop isn't a great plan).