Reputation: 263
I have started putting charts in my app. Initially I did this using CGMutablePath() but then refactored it to us NSBezierPath(). I find it confusing which I should be using but given the "NS" in NSBezierPath() I wondered whether thats the old way and I should be using CGMutable path.
Can someone please let me know whether I should be using one or the other ? If it's either then how do you decide which to use ? For what I was doing NSBezierPath produced simpler code.
I'm using SWIFT 4 and XCode 9
Thanks Steven
Upvotes: 1
Views: 508
Reputation: 16327
The CG stands for core graphics and is the C style graphics API. Being C it’s not object oriented and requires that you pass in pointers for things like the graphics context or the CGPath although in Swift 3 this gets papered over with some syntactic sugar because the compiler now does this for you and makes the api appear object oriented even though it is not (look at the objective c vs the swift documentation for any CG function and you can clearly see the difference). The NS functions are the object oriented objective C wrappers around the CG functions. You see this in many of apples API’s for example CFString (the C version) and NSString (the objective C version). I believe the Apple recommendation is to use the highest level API unless you have some reason to do otherwise although people routinely ignore this rule. For instance I almost always see people use GCD to access the main thread instead of NSOperationQueue. Use whichever API you like; it doesn’t really matter so much in swift as it does in Objective C, C or C++.
Upvotes: 2