Xcode Tip: Organize your source code
One can (IMHO should) take advantage of some of the formatting techniques inbuilt (but obscured from the user) in Xcode. In this post I will discuss two such techniques:
1. Indentation: So you copy-pasted some code from apple’s tutorials and want to reuse it in your source code. Oh, but wait ! The formatting is all screwed up. You don’t want to indent every line ! Fortunately, XCode provides a hidden trick to reformat your code. All you have to do is copy your entire source code file and delete it and paste it back in. So, Command-A(select all), Command-C (to copy), Command-V(to paste) and BINGO !
2. Organizing methods (using #pragma): With Delegation, a single view controller in your source code can become a delegate of a lot of other view controllers. As a result, it will contain the delegation methods of all those view controllers. Its a good practice to group the delegation methods together and give that a label so that when you view the method list at top of the source editor, the grouped method will show up together under the group header of your choice. This can be achieved by using the following syntax in source code:
#pragma mark <some label name>
method 1
method 2
.
.
#pragma mark-
No comments yet.