user387184
user387184

Reputation: 11053

how to create new class files based on existing ones - in Xcode

Is there a way to create a new class based on another which already exists in the project?

Ideally one could just make a copy of a group (which may inlude .h, .m -xib) and change whatever code on this copy to create a new class.

Currently I create a new group, create the new class with it's new name and then copy the code for these files - immediately renaming the old class name into the new class name

The alternative would be to do "Show in Finder" and create duplicates for the files, drag them back into xCode, create a new group and drag them there...

Is there some better way to do this?

ps in Eclipse there is even an explicit option in the menu for this purpose

Many thanks

Upvotes: 1

Views: 326

Answers (1)

rdurand
rdurand

Reputation: 7410

I think you should use a subclass for that. Create a new Objective-C class, and choose your old class as the parent class.

Have a look a this, it may help you understand this principle if you're not familiar with it : http://www.techotopia.com/index.php/Objective-C_Inheritance

The concept of inheritance brings something of a real-world view to programming. It allows a class to be defined that has a certain set of characteristics (such as methods and instance variables) and then other classes to be created which are derived from that class. The derived class inherits all of the features of the parent class and typically then adds some features of its own.

I don't know what will happen to the xib file, but at least you can re-use your classes as much as you want !

Upvotes: 1

Related Questions