Search code examples
iosxcodeautomated-refactoring

Xcode extract refactor not working – "Can’t extract this selection."


If I try to perform an Xcode "extract" refactor, I get the error:

Can’t extract this selection.

Select source code in a function or method body and try again."

It doesn't seem to matter what I select to extract. What I have selected certainly is part of a method body.

I'm using Xcode 7. The code has successfully compiled and it's finished indexing.

There are some suggestions in this post about white space confusing the tool, but these do not seem to be the issue in this case.

Anyone know how to fix, or how to diagnose further?


Solution

  • It turns out that the code file I was working on contained an unbalanced bracket coding error in it. The error was much further up the file. It was hidden or ignored because it was within a macro call.

    While the file compiled without problems, I noticed that Xcode's indentation and code balancing seemed to be up the creek and in tracking it down discovered the unbalanced brackets issue.

    After fixing the unbalanced brackets, the extract refactor now works perfectly.

    If you happen to have got here, check that there aren't unmatched brackets in your source.