Redundant Constructors


From the department of coding redundancy department , a few favorites.

There’s something about an API entirely made up of capitals that makes the heart sing:


This AV Foundation constructor is particularly fun to say out loud. Try it!

AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:player];

Sure, there are lots of class constructors that allow you to build instances but building an instance with an instance that sounds so class-name-like is particularly special.

NSString *string = [NSString stringWithString: _string]; // Thanks, Mike Ash

This last one is so deliciously long.

AVCaptureAutoExposureBracketedStillImageSettings *bracketedStillImageSettings = [AVCaptureAutoExposureBracketedStillImageSettings autoExposureSettingsWithExposureTargetBias:targetBias]

There are plenty of similar ones out there. Find a goodie? Drop an email, a comment, or a tweet, and let me know.

One Comment

  • I actually despise my devs, when they create + (instancetype)viewController { return [FooViewController alloc] init]; } But for more complicated things, it makes sense.