14 ms·
It's interesting how much of the Foundation consists of patterns for overcoming the awkwardness of Objective-C. For example, in most modern languages, NSCounte
by mistercow 14y ago
It's interesting how much of the Foundation consists of patterns for overcoming the awkwardness of Objective-C.
For example, in most modern languages, NSCountedSet is crazy trivial; you just use a hash of numbers. But since Obj-C doesn't have autoboxing (well, it kinda sorta does nowadays, but anyway), having a built in implementation is nice.
NSValueTransformer is a similar workaround for a lack of language features, which will look particularly alien if you're used to languages with proper closures and autoboxing. They are a boilerplate nightmare, and Apple would have done well to provide some simple implementation that could be controlled from the interface builder years ago (based on JavaScript expressions, for example).
Anyway, a fun exercise with NSValueTransformers is to build a subclass for chaining them together (bonus points for automatic reversing), and then a subclass of simple primitive operations that you can compose into more complex transformers. This can actually be pretty useful if, for example, you have a number of log-scale sliders and text fields that require slightly different transformation parameters.
- mistercow 14y agoI think my above comment may have come across as unnecessarily harsh against Objective-C. I like Obj-C and I was actually trying to make a broader point: you can often learn a lot about a language's weaknesses and quirks by digging into its standard library.