Search code examples
iosobjective-ciphonexcodecocoa-touch

How do you duplicate a file in XCode?


Anyone know a good solution?

So far I have not found a better way than using File>New file and then copying contents from old file to new.

You can probably duplicate in Finder and re-import but that's almost same amount of work: switching to finder, duplicate, import new files.

Doing this with one class is not so hard, but what to do if you need to generate 10+ similar Classes based on superclass.

In Eclipse you select file and then copy/paste it in same folder. In finder there's Duplicate.

There's a menu Edit > Duplicate. But it's ALWAYS disabled. I tried selecting various files, classes, methods. It's still disabled.


Solution

  • "Duplicate" is enabled for targets in XCode (pretty much nothing else that I know of).

    If you have a substantial number of subclasses with the same starting point to replicate, why not make a class template from it? Then you can just use file->New to make new instances. It's fairly quick to do.

    This is probably the simplest example:

    http://www.macresearch.org/custom_xcode_templates

    Otherwise, I'd simply duplicate the files in Finder as many times as you need, name them, and drag them into XCode en-masse.