Why are some libraries in iOS provided C based API? For example, Core Graphics library is provided by C based API. But, I can’t understand the reason why Apple did it.
Moreover, [[UIColor red] setStroke] which is the kind of code in drawRect: also makes me confused! If Apple decided to use C based API, why do they use object oriented style code doing graphic things?
And CGContextAddLineToPoint(), for example, takes argument CGContextRef c. I think it’s completely suitable to use object oriented things.
// current
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextMoveToPoint(context, 0, 0);
CGContextAddLineToPoint(context, 10, 10);
// looks better
CGContext *context = [UIGraphics getCurrentContext]
[context moveToPoint: CGMakePoint(0, 0)] // or [context moveToPointX: 0 y: 0]
[context addLineToPoint: CGMakePoint(10, 10)] // or [context addLineToPointX: 10 y: 10]
So, why does Apple use C based API on some libraries?
Performance