Reputation: 578
I am using XCode 4. I have a very long .m file with a lot of function implementation.
I'd like to sort the functions alphabetically by their name or by its return type or the same order in its .h file.
The purpose of this is to better organize my .m file. I recently rearranged the functions in its corresponding .h file and it would be great if their is an automatic way of sorting the function implementation the same way its ordered in the .h
Here is an example of what I have now.
Currently have.
.h file
-(void) a;
-(void) b;
-(void) c;
.m file
-(void) c;
-(void) a;
-(void) b;
I'd like .m to sort the same way .h is sorted. I really hope this is possible without me copy pasting. The file is thousands of lines long.
Upvotes: 2
Views: 951
Reputation: 8423
Cannot find a sorting function anywhere. But actually I find it more useful to group methods by its kind and use the pragma mark. E.g. all the MKMapViewDelegate methods come after the following pragma comment
#pragma mark MKMapViewDelegate
This allows you to find methods more easily when you use the drop down right above the editor.
Apart from this the only best way to easily do the cut&paste job is to fold all the methods using menu Editor -> Code Folding -> Fold Methods & Functions as already pointed out by idz.
Also I would consider re-factoring of your class. Can you create several classes? Maybe you have utility methods that you can move into a general purpose utility class?
Upvotes: 2
Reputation: 6128
If you hold down the command key while selecting the function popup in Xcode4 then the messages will be listed in alphabetical order.
Class messages(+) will be sorted before instance messages(-).
Upvotes: 5
Reputation: 12988
I do not know of a way of doing this automatically in Xcode, but the following may make doing it manually quicker. Open the implementation file. Then do Editor > Code Folding > Fold Methods & Functions. Now all your methods will have been folded down to one or two lines each, depending on your coding style. You can now select a function and drag it to its new position to achieve the ordering you want.
If you need to refer to the header file to ensure the order is correct, try doing this in the assistant view; that way you can see the header file and implementation file side by side.
Upvotes: 2