123

Currently I'm working on an iOS based Image Manipulation task.

Problem:

I'm working on different modules. So If I need to add something in a module in future, I want to mark it as a To do note. Are there any other macros or similar to add a to do note in Xcode ?

I tried:

For this currently I'm using #pragma like:

#pragma mark -
#pragma mark To do: Add the Image processing methods.

I got:

But it lists in the Method section like:

To Do

What I actually need:

The issue is, it's listed under the methods list so sometimes I forgot to remove this from the section also it's very difficult to find it in entire source code. (Searching #pragma results to show entire lists)

Technical Details:

I'm using Xcode Version 4.6.2 .

5
  • 1
    How do I get to that particular view where Xcode lists all the methods, pragma marks and TODO annotations?
    – Mischa
    Commented Jan 30, 2014 at 10:41
  • @Mischa: Check my answer, It's under the method listing bar.
    – Midhun MP
    Commented Jan 30, 2014 at 11:28
  • I did check your answer and did not find a hint how to show that pop-up. But I think I found it now: It's on top of the code editor in that "navigation" bar, right?
    – Mischa
    Commented Jan 30, 2014 at 13:49
  • Btw: Is there any way to show all of the project's TODOs at once?
    – Mischa
    Commented Jan 30, 2014 at 13:50
  • @Mischa: Yes it's on the top of code editor, and in my knowledge there is no way to display all to do comments at once (Instead of searching the whole project)
    – Midhun MP
    Commented Jan 30, 2014 at 13:59

10 Answers 10

156

I got it.

Writing comment like:

// TODO: Do something

Will do the trick.

I got something like:

TO DO


Also there is a lot of options like:

  1. // FIXME: Midhun

  2. // ???: Midhun

  3. // !!!: Midhun

  4. // MARK: Midhun
13
  • 19
    you can also use //FIXME: or #warning. when you use #warning, you got a warning in Xcode and you can jump directly to that part.
    – brush51
    Commented Jun 4, 2013 at 8:48
  • 6
    Isn't that what @Dev2rights posted an hour before you? Why don't you accept his answer?
    – trojanfoe
    Commented Jun 4, 2013 at 11:32
  • @trojanfoe: yes. But I got a more apt solution for me //MARK: and #warning. That's why I didn't accepted it
    – Midhun MP
    Commented Jun 4, 2013 at 11:53
  • 1
    Well // FIXME, // MARK and #warning aren't the same as // TODO and so that doesn't answer your question.
    – trojanfoe
    Commented Jun 4, 2013 at 11:55
  • 1
    @Domsou: Currently there are no other options available rather than the listed ones. I'll update my answer if I get any.
    – Midhun MP
    Commented Aug 29, 2013 at 12:29
136
// TODO: the thing todo

Is how you show todo tasks.

4
  • 10
    You can also use // FIX: Everything crashes all the time to make it easier get back to parts of your code that generate issues using the Jump Bar.
    – Maarten
    Commented Jun 4, 2013 at 8:50
  • Strangely using this does not show the comment in XCode 5.1.1 Commented Jul 1, 2014 at 13:12
  • 2 more markers that seem relevant here are #warning and #error i.imgur.com/KVjrVwG.png Commented Sep 23, 2015 at 15:10
  • 3
    Nitpick: Put a space between the // and TODO:. For example: // TODO: Read this from prefs. If you review documentation of the Swift and Objective C languages, this space convention is fairly consistently followed.
    – Goffredo
    Commented May 3, 2016 at 20:26
48

Using the

//TODO: some thing here

works if all you want to do is to look at the list of todos in the drop down

If you want to be intrusive you can use #warning marks instead:

#warning this will create a compiler warning.

And when you build the app you will get a compiler warning (a yellow triangle, not a compiler error) which is a little more "in your face" about reminding you of things you need to do.

1
  • I think #warning is the best solution because it will warn you at compile time. Thanks
    – Duck
    Commented Mar 1, 2016 at 14:32
39

With the script below your can see all required tags like warnings.

  1. Select your project in the Project Navigator
  2. Open the target in the sidebar and move to the "Build Phases" tab
  3. Click on "+" sign
  4. Select "New Run Script Build Phase" Script adding
  5. Add below script to "Run Script" Ready Script The script:

    KEYWORDS="TODO:|FIXME:|DevTeam:|XXX:"
    find "${SRCROOT}" \( -name "*.h" -or -name "*.m" -or -name "*.swift" \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($KEYWORDS).*\$" | perl -p -e "s/($KEYWORDS)/ warning: \$1/"
    

enter image description here

Original answer was taken from Here

Another alternative is XToDo plugin for Xcode.

2
  • great solution, is there a way to exclude all the pod files? there are a couple of Todos oder Mixmes in my used extensions? Commented May 2, 2018 at 17:43
  • found a solution by myself in this post stackoverflow.com/q/37157027/6003494 the script is: KEYWORDS="TODO:|FIXME:|\?\?\?:|\!\!\!:" find "." \( -name "*.h" -or -name "*.m" -or -name "*.swift" \) -not -path "./Pods/*" -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($KEYWORDS).*\$" | perl -p -e "s/($KEYWORDS)/ warning: \$1/" Commented May 15, 2018 at 18:24
9

I started with

// TODO: Implement bubble sort.

Then I joined a large project and sometimes I needed a todo to live longer than a WIP commit and so to distinguish my todos from my peers I name spaced my todo with my initials:

// TODO: SM: Implement bubble sort

Sometimes I wanted more visibility so I started to use pragma warnings in some places.

#warning Implement bubble sort

One day I decided to turn on hard mode by adding -Werror to my cflags. Unfortunately this makes pragma warnings useless because they prevent compilation. And so I went back to using // TODO: until Jeff Nadeau told me that I can put

-Wno-error=#warnings

in my cflags so as to not treat pragma warnings as errors. So now #warning and -Werror can live along side each other.

7

You can use XToDo plugin

https://github.com/trawor/XToDo

use ctrl+t to trigger the List Window on/off

use ctrl+t to trigger the List Window on/off

Toolbar exemple

Easy install with alcatraz use ctrl+t to trigger the List Window on/off

1
  • 1
    Was scrolling down to suggest that, completely recommend. Commented Apr 17, 2015 at 8:15
5

I tend to write exactly:

//TODO: Blah blah blah

Then I just do a COMMAND-SHIFT-F and look for "//TODO".

Using the file outline drop down will only show you TODOs for the current file, but I tend to want to see my project's TODO status.

Rough solution, but it does it's job.

2

I split up the recognized tokens into Warnings and Errors for my own use, thought I would share it here:

KEYWORDS="STUB:|WARNING:|TODO:|FIXME:|DevTeam:|\?\?\?:" 
find "${SRCROOT}" \( -name "*.h" -or -name "*.m" -or -name "*.swift" \) -not -path "${SRCROOT}/Pods/*" -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($KEYWORDS).*\$" | perl -p -e "s/($KEYWORDS)/1: warning: \$1/"

KEYWORDS="ERROR:|XXX:|\!\!\!:" 
find "${SRCROOT}" \( -name "*.h" -or -name "*.m" -or -name "*.swift" \) -not -path "${SRCROOT}/Pods/*" -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($KEYWORDS).*\$" | perl -p -e "s/($KEYWORDS)/1: error: \$1/"
ERROR_OUTPUT=`find "${SRCROOT}" \( -name "*.h" -or -name "*.m" -or -name "*.swift" \) -not -path "${SRCROOT}/Pods/*" -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($KEYWORDS).*\$" | perl -p -e "s/($KEYWORDS)/1: error: \$1/"`

exit ${#ERROR_OUTPUT}
0

Another simple method, slightly outside the box, if you don't want to clutter up the methods listing bar, is to use a convention within comments like //Todo: and when you want to address them en-masse, simply select the Find Navigator, match case and search for //Todo:

I prefer this as I don't like the methods drop down looking like spagetti-code. And yes, I often have lots of Todo:'s ;)

0
#error

and

#warning

are also used in C programming

Not the answer you're looking for? Browse other questions tagged or ask your own question.