I set up my BEMSimpleLineGraph and was able to do it successfully, except for linear gradient shading. After referencing this code in the above Obj-C project example
CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB(); size_t num_locations = 2; CGFloat locations[2] = { 0.0, 1.0 }; CGFloat components[8] = { 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0 }; self.myGraph.gradientBottom = CGGradientCreateWithColorComponents(colorspace, components, locations, num_locations);
and rewriting it in Swift:
let colorspace:CGColorSpaceRef = CGColorSpaceCreateDeviceRGB() let num_locations:size_t = 2 var locations: [CGFloat] = [0.0, 1.0] var components: [CGFloat] = [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0 ] self.myGraph.gradientBottom = CGGradientCreateWithColorComponents(colorspace, components, locations, num_locations)
everything builds correctly, but generates an EXC_BAD_ACCESS memory error in the BEMLine.m file, which stops on this line
CGContextDrawLinearGradient(ctx, self.bottomGradient, CGPointZero, CGPointMake(0, CGRectGetMaxY(fillBottom.bounds)), 0);
I included the obj-c bridge title, added the CoreGraphics structure, turned on the bottom color in the attributes panel of the corresponding ViewController in the Storyboard, linking to the Apple development pages to ensure the correct data types of all parameters, but I'm still dry. When checking the similarity of errors, I also realized that the same error occurs when trying to draw an upper linear gradient. The error seems to be in Obj-C code trying to draw a gradient, but again I donβt understand what to do.