1

My team have inherited a large, unruly iOS codebase from an agency, and we’re trying to use some automated tricks to refactor it. One strange decision we’re up against is an abundance (thousands) of things like this:

UIImage *result = nil;
UIGraphicsBeginImageContextWithOptions(size, opaque, scale);
{
    block(UIGraphicsGetCurrentContext());
    result = UIGraphicsGetImageFromCurrentImageContext();
}
UIGraphicsEndImageContext();
return result;

I’m talking about the braces, that are arguably there for no good reason whatsoever. What I’m keen to do is find a way to remove them.

I’m wondering whether I can find some clever way to remove these redundant braces, and re-indent the code inside them, without touching other things that use curly braces.

AppCode’s refactoring tools haven’t helped, and although a simple find and replace could work for the opening curly braces, it’d find the end of every if statement for the closing ones.

Conundrum. Any ideas? Multiline regex, can Xcode even do that? Can AppCode? I need to apply it across an entire project automatically, whatever it is.

Luke
  • 9,512
  • 15
  • 82
  • 146
  • I just discovered that Xcode can't do that but AppCode can. See my Q&A: http://stackoverflow.com/questions/37083126/how-can-i-use-xcodes-find-and-replace-on-multiline-blocks-of-text/37089590#37089590 – Dave Chambers May 07 '16 at 14:29

0 Answers0