How to use Xcode Extract refactoring feature?

 ̄綄美尐妖づ 提交于 2019-12-13 02:23:28

问题


How do you use Xcode's Extract refactoring tool?

Whatever code I select, I always get the same unhelpful error message.

The selection does not contain anything that can be extracted. Make a different selection and try again.

See the screenshots below:

What do I need to follow to have it work?

I am doing this on a simple iOS project, nothing special, no C++. Tried with the latest version of Xcode (4.4) and the newer latest developer preview releases.

Is this a bug? Any workaround?


回答1:


For some strange reason if you have a block that doesn't create an obvious return value of pick up parameters XCode complains if you include the newlines. In my opinion this is a bug, as whitespace should be ignore. Just make sure you don't include the newlines. For example, the following works with "Refactor > Extract Method":




回答2:


Automated refactoring tools first check that certain preconditions are true before applying the requested refactoring. In this case, it seems that the preconditions failed. I've done plenty of similar Extract Method refactorings in XCode and I can't why there's a problem with the code you selected. Perhaps there's some subtle dependency that isn't apparent in the code you show.

I'm not sure if I'd call this a bug. In developing a refactoring tool the developer can always make the preconditions a bit weaker at the price of more complicated refactoring logic.

Doesn't solve your problem but perhaps is of some help.



来源:https://stackoverflow.com/questions/11802901/how-to-use-xcode-extract-refactoring-feature

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!