Last Updated: February 25, 2016
·
942
· brayden

Xcode Locating Areas of Interest

If you've ever had a semi-large main file in your Xcode project then more than likely you've had a little difficulty locating the part of the file you're trying to access or edit. Quite possibly you could have forgotten where you wanted to change a snippet of code at some point as well, and now it's time for you to locate and replace it - how we can we make it all easier?

Pragma Mark
For separating all distinct sections in your files you should really use pragma marks to their fullest. Why? They allow for much cleaner code and separation. In your method drop down (the bar right above your file you're editing, very right option) if you select it you see a list of all your methods, defines, and also... in bold... pragma marks which can easily settle to be used for titles of sections (i.e. - IBAction Methods, UITextField Delegate Methods, etc).

#pragma mark -
#pragma mark Section Title
#pragma mark -

Is often seen, but can be simplified as:

#pragma mark - Section Title -

It helps make your code much easier to access and also much more readable.

TODO:
When you know you're going to be coming back to edit a piece of code in the future, you should mark it somehow. Using a comment marked "TODO:" notifies Xcode that this is an important piece of code that should be also placed in the method drop down where pragma marks also show. So now when you're trying to find a piece of code to change that you had a TODO next to - it's quite easy.

Example:

// TODO:  Replace this static string with a formatted string

2 Responses
Add your response

You can use FIXME: in a comment if you want to mark a section of code which you now that has to be fix.

// FIXME: change the way this algorithm work
over 1 year ago ·

@alexcristea Thanks for adding to it and pointing that out!

over 1 year ago ·