Definitely. I only parsed through the names, ratings, and years. Going back to parse more stuff such as the number of votes, genre, etc. is going to be the most painful part of this project.
I'm not really sure I understand; why would calling the method "capitalize" instead of "capitalizeInPlace" be inconsistent?
(Also, the comments in the header file and the README file contain the name "capitalizedStringInPlace" instead of "capitalizeInPlace")
Another inconsistency is that most mutating methods in ObjectiveC don't return self, but either void or a boolean or an integer that reports if the method succeeded. But I assume that this inconsistency is on purpose because you want to make the methods chainable.
The issue with the default syntax in NSString is that the mutating methods are the more concise, but are also the ones you use the least. It makes far more sense for the more used methods to be more concise than their mutating siblings.
I don't disagree with you though. I'd prefer if the interface for this was more idiomatic.
Returning void is sort of pointless. A boolean, maybe. I feel like returning self is just making better use of things, really, and probably doesn't really cause any confusion.
Okay, now I get it, the naming makes autocomplete more convenient.
Returning void makes it easier to spot errors. If you accidentally use "capitalizeInPlace" instead of "capitalizedString" your code will compile without issues. If the mutating method returned void, it would result in a compile error.
There are already a lot of Ruby categories out there. ObjectiveSugar covers a lot of bases. I personally wouldn't import more Ruby categories. The NSString API is a weak point of Cocoa, IMO, but in general I wouldn't like to see a large amount of unique, dependent, astonishing code.
Unfortunately, although there's no particular reason for it, you're not allowed to write a method that takes only variadic arguments. This doesn't work:
- (NSString *)format: ...;
It would be oh-so convenient, meaning you could write formatting operations like this:
- (NSString *)format:(id)first, ... {
NSUInteger argCount = 0;
BOOL prevPercent = NO;
for (NSUInteger i = 0; i < [self length]; ++i) {
unichar c = [self characterAtIndex:i];
if (prevPercent && c != '%')
++argCount;
prevPercent = c == '%';
}
NSMutableArray *argArr = [NSMutableArray new];
va_list args;
va_start(args, first);
for (NSUInteger i = 0; i < argCount; ++i)
[argArr addObject:va_arg(args, id)];
va_end(args);
switch (argCount) {
case 0: return [NSString stringWithFormat:self, first];
case 1: return [NSString stringWithFormat:self, first, argArr[0]];
case 2: return [NSString stringWithFormat:self, first, argArr[0], argArr[1]];
// ...
}
}
Only supports NSObject arguments, obviously. If you actually wanted to do this approach you'd want to do a better job of parsing the format string and use a more cleverer way of storing the args.
Or, for the completely insane approach that probably doesn't actually work (on top of being entirely unportable):
The problem people have with the format implementation is that no matter what you do, it's either obtuse shorthand, or incredibly verbose.
The reality is, that NSString needs native formatting sugar. Anything else would really just be a hack. I'm not particularly even happy with the [@"Hello ":@"World] syntax, either.
I'm not super comfortable with breaking message syntax like that. Also, very wary of using a #define with a short oft used keyword in a library that will be imported in majority of headers.
And you changing the category won't help the versions already out in the wild. Hopefully, automatic updates will mitigate this to some degree but not everyone will turn them on.
There are workarounds (like prefixing methods with a pseudo-namespace), but they're all a bit ugly. Might be worth considering though.