Convenience init extension for CG/CF types

Why can’t I write a convenience init extension for CG/CF types ? Is it about ARC (releases) ?

Error: Convenience initializers are not supported in extensions of CF types

Although it doesn’t really answer the question, this might provide some insight: SR-1801

Let’s wait for someone from core (or someone who knows) to elaborate on this.

No, that’s pretty much the answer.

Specifically, convenience initializers can be inherited, and your new one can’t be in a safe way. The feature we need here is what we call “factory initializers” inside the compiler. (It’s not out of the question, either! Just still needs some design.)

A convenience initializer always has to return the Self type, but you can’t guarantee that with the “initializers” that get imported from C. Those only promise to return one particular type.

Does this mean CGPath, or rather Core Graphics, is a C framework bridged to Swift?

Oh, it really is! (Core Foundation) CFArray.c

Ah, the latter. Frameworks built on Core Foundation are C-compatible (though they do use Objective-C in their implementation).

2 Likes