I’ve found this in the CGPath.h header file. I’m curious what this const thing does?
typedef struct CGPath *CGMutablePathRef;
typedef const struct CGPath *CGPathRef;
My guess: If I typedef something as const, it’s constant so immutable and can’t be changed in any way. Does that make sense?
Yes the
constmeans you cannot change the path externally.For CoreFoundation-based libraries though, the
constis more a hack to allow mutable objects to use immutable methods without casting, and not vice-versa. That meanscompiles fine because a
Foo*can be implicitly converted to aconst Foo*, butwill throw an error because a
const Foo*cannot be safely converted to aFoo*.