What is the difference between CGPath and UIBezierPath()?

BrianCO picture BrianCO · Aug 23, 2014 · Viewed 7.8k times · Source

At the moment, I'm trying to work out how to animate a custom button which I have an image of and have the coordinates of but I've found that you can create a button/object both by using the CGPath class or the UIBezierPath class. Can somebody please tell me what the difference between the two are?

Answer

jtbandes picture jtbandes · Aug 23, 2014

CGPath is an opaque type from the CoreGraphics library, while UIBezierPath is an Obj-C class in UIKit. UIBezierPath is a wrapper around CGPath (you can convert between them easily), with a more object-oriented interface and a few convenience methods. Using CGPath may be marginally faster as it doesn't have to go through Obj-C (although who knows how it works with Swift) and it has more advanced functions like CGPathApply. Importantly, UIBezierPath conforms to NSCoding, meaning you get serialization/deserialization for free.

tl;dr: use UIBezierPath unless you have some reason not to.