Renaming Document Classes in Cocoa03/27/07Renaming Document Classes in CocoaI've been learning Cocoa on OS X lately. One of the things I've been experimenting with is document based applications. I've been working on an application that processes Par and Par2 files. So, in the process of developing this application, I needed to write a document based application to view the contents of the files. The problem is, XCode doesn't prompt you for the name of the document class when you tell it to generate a new Document based application. Instead, it generates a document class called 'MyDocument'. This is obviously not a very useful class name. When XCode generates this MyDocument class, it also generates the MyDocument.nib file and connects everything together for you. The problem is, if you try to rename the document, all those connections break and the document and NIB stop working together. Plus, if you want to generate a second document/NIB, you are on your own. I wanted to document how to manually rename a Document class/NIB so that the connections between them continue to work. For this example, I'll use the example of renaming 'MyDocument' to 'ParDocument' (which is what I did in my application). If you want to use a different class name, just substitute your class name for everywhere that I mention 'ParDocument'. Generate the new Document class
Generate the new NIB file
Set the Document Class for the Document
hat's it! Now that everything is connected for your new ParDocument class, you can go ahead and delete MyDocument.h, MyDocument.m and MyDocument.nib from the project. It's a long, involved, and very confusing process to do this. Hopefully this has helped you. 3 commentsThank you!
04/19/07 @ 13:41
04/26/07 @ 14:07
Comment from: Bill Hernandez [Visitor]
( 1 ) Select the Classes folder, then the MyDocument.m file ( 2 ) Double Click on "MyDocument" next to the @implementation ( 3 ) Select MenuBar --> Edit --> Refactor and a dialog will appear ( 4 ) Rename should be selected from the popup menu, change the textField to "ParDocument" or whatever you want, and Click Preview, and Apply Button, and Wait till it is done. ( 5 ) At the top of the ParDocument.m file Double Click MyDocument, and do a CMD-E, and a CTRL-CMD-E, then a CMD-SHIFT-F ( 6 ) In the Replace field change MyDocument to ParDocument, or whatever you want. The popup menu's should have : "In Project" "Textual" "Whole words" ( 7 ) select all the items found and click on Replace, then hit Find again to make sure there are no more items found. ( 8 ) Open the Resources folder and rename MyDocument.xib to ParDocument.xib ( 9 ) Hit CMD-R to run, and you should see a document window open
03/21/10 @ 22:07
|