Regex replace and CGPointMake with Xcode

If you’re using PaintCode you might want to have drawrect code that scales depending on your needs. I’m sure there are multiple ways to achieve this. I use the help of two macros I call “MyMacroForX” and “MyMacroForY” for now which translate the given float value based on the dimensions of the UIView I set in Interface Builder or code. Unfortunately PaintCode does not provide you anything to help with adding those macros to it’s generated code.

Let’s assume you have a more complex shape than a circle, multiple layer and so on. You end up pretty quickly having lots of CGPointMake calls like
CGPointMake(34.54, 87.28)

but want something like
CGPointMake(MyMacroForX(34.54), MyMacroForY(87.28))

The Solution:

Xcode offers search and replace based on regular expressions which is a great solutions if your don’t want to spent an hour copy & pasting.

Xcode regex replace settings

Set the style in your Replace options to Regular Expression. It’s also useful to define a custom search scope for the upcoming task (if your don’t want to replace all occurrences in your project).
The find pattern I use looks like this
CGPointMake\([-+]?([0-9]*\.[0-9]+|[0-9]+), [-+]?([0-9]*\.[0-9]+|[0-9]+)\)

As replace pattern I use
CGPointMake(MyMacroForX(\1), MyMacroForY(\2))

This saved me a lot of time in the past and I’m sure it will in the future.