Block Syntax is Ridiculous

I love blocks and hate block syntax. It seems so arbitrary!

Consider literal Blocks

^returnType(Type param1, Type Param2) {

Vs. Block Variable Definitions

returnType(^variableName)(Type, Type)

Vs. Block Parameter Definitions


What’s going on with the ^ operator, which lives outside parentheses in a block literal but inside in a block parameter?

Why does the parameter name go at the end of the block type declaration, while the variable name goes right in the middle of the type declaration–unlike every other C variable you’ve defined?

Update, as Peter Hosey helpfully pointed out:

And WHY does the return type go outside the ^ in a parameter and variable definition but inside the ^ in a block literal?

It’s like Apple did everything in their power to make sure it was inconsistent. I’m almost surprised that the parameter list isn’t nil terminated when you pass in parameters, but maybe they didn’t think of that.


CGGeometry.h Silliness

Given a rectangle whose edges can be specified by the lines y = 10, y = 50, x = 5 and x = 25:

Q1, Q2: What should the Max and Min X be?
Q3, Q4: What should the Max and Min Y be?

If you’re using the CGRectGetMax family of functions, the answers are:

A1: CGRectGetMaxX = 25
A2: CGRectGetMinX = 5
A3: CGRectGetMaxY = 50
A4: CGRectGetMinY = 10

That seems logical, however this is contrary to the documentation which states that CGRectGetMaxY returns the TOP EDGE of the rectangle, which should be Y = 10 when you’re using UIKit.

But no, the top edge is 50 when whenever the user space is AppKit or Quartz, which was most of Apple’s history up to this day.


Disappointed in XCode/clang today.

The following line of code doesn’t compile:

UIButton *searchBtn = [[UIButton alloc] initWithFrame:{CGPointZero, image.size}];

But this line does:

UIButton *searchBtn = [[UIButton alloc] initWithFrame:(CGRect){CGPointZero, image.size}];

My computer knows who my mother and father are, where I live and where I go to work. Why can’t my computer detect properly typed struct literals when they’re input to strongly typed struct parameters?

Such a fail.