I’m using DCRoundSwitch for a project where I basically need an UISwitch where I’m able to edit its label contents.
Because I’m using ARC I refactored the DCRoundSwitch code to be ARC-compatible in xcode.
When compiling and running in the simulator it works without any problems.
However, when running on the device it gives me EXC_BAD_ACCESS near line 57 of DCRoundSwitchKnobLayer.m
There is a bug report at GitHub but no solution has been found yet.
Here is the code that gives EXC_BAD_ACCESS:
CGGradientRef CreateGradientRefWithColors(CGColorSpaceRef colorSpace, CGColorRef startColor, CGColorRef endColor)
{
CGFloat colorStops[2] = {0.0, 1.0};
CGColorRef colors[] = {startColor, endColor};
//THIS LINE BREAKS THE PROGRAM
CFArrayRef colorsArray = CFArrayCreate(NULL, (const void**)colors, sizeof(colors) / sizeof(CGColorRef), &kCFTypeArrayCallBacks);
CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, colorsArray, colorStops);
CFRelease(colorsArray);
return gradient;
}
Any clues would be appreciated.
EDIT: Here are the local variables from xcode:

colorsArrayis released using the methodCFRelease. ARC doesn’t allow the use ofretainandrelease, so why don’t you try commenting the lineCFRelease(colorsArray)and see if that prevents the error?Edit–
This answer was accepted as it supplied a valid fix to the OP’s issue, by disabling ARC.
If you do not want to use this method, please see @petesh’s answer.