122

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 .

alexwlchan
  • 5,699
  • 7
  • 38
  • 49
Midhun MP
  • 103,496
  • 31
  • 153
  • 200
  • 1
    How do I get to that particular view where Xcode lists all the methods, pragma marks and TODO annotations? – Mischa Jan 30 '14 at 10:41
  • @Mischa: Check my answer, It's under the method listing bar. – Midhun MP Jan 30 '14 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 Jan 30 '14 at 13:49
  • Btw: Is there any way to show all of the project's TODOs at once? – Mischa Jan 30 '14 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 Jan 30 '14 at 13:59

10 Answers10

155

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
Chris Nolet
  • 8,714
  • 7
  • 67
  • 92
Midhun MP
  • 103,496
  • 31
  • 153
  • 200
  • 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 Jun 04 '13 at 08:48
  • 6
    Isn't that what @Dev2rights posted an hour before you? Why don't you accept his answer? – trojanfoe Jun 04 '13 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 Jun 04 '13 at 11:53
  • 1
    Well `// FIXME`, `// MARK` and `#warning` aren't the same as `// TODO` and so that doesn't answer your question. – trojanfoe Jun 04 '13 at 11:55
  • @trojanfoe: Ya, that's true. But when I use #warning each time, i'll get a warning so I never forgot the place where I put it also. Always remember the pending things (It's not same as TODO but for me it can solve my headache) – Midhun MP Jun 04 '13 at 11:58
  • @Daij-Djan: I also said the difficult of using #pragma, because often I forgot in which module I put it. So #warning is easy for me to remind this – Midhun MP Jun 04 '13 at 12:15
  • yes, it sure is :) im in no way disagreeing ;) I mearly stated how I saw it -- same as trojonfoe – Daij-Djan Jun 04 '13 at 12:32
  • @MidhunMP Can you publish all the options available if there others ? Or at least publish a link on the source document ? Thanks – Dominique Vial Aug 29 '13 at 08:40
  • 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 Aug 29 '13 at 12:29
  • These do not appear to work inside functions as of Xcode 5.1. – Dan Loewenherz Jan 01 '14 at 16:25
  • I used this often, but now, with Xcode 6.4 it doesn't appear to work for me any more. Anyone else? – Thomas Tempelmann Jul 14 '15 at 13:15
  • @ThomasTempelmann: I'm using Xcode 6.4, and it is still working for me (In swift these markers are the only available alternative for #pragma, so it should work) – Midhun MP Jul 14 '15 at 13:42
  • what is the source of these marks? and what does it mean !!! or ??? – João Serra Jun 29 '22 at 14:37
134
// TODO: the thing todo

Is how you show todo tasks.

Iulian Onofrei
  • 9,188
  • 10
  • 67
  • 113
Dev2rights
  • 3,469
  • 3
  • 25
  • 42
  • 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 Jun 04 '13 at 08:50
  • Strangely using this does not show the comment in XCode 5.1.1 – loretoparisi Jul 01 '14 at 13:12
  • 2 more markers that seem relevant here are #warning and #error http://i.imgur.com/KVjrVwG.png – Zane Helton Sep 23 '15 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 May 03 '16 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.

Abizern
  • 146,289
  • 39
  • 203
  • 257
  • I think `#warning` is the best solution because it will warn you at compile time. Thanks – Duck Mar 01 '16 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.

razor28
  • 1,077
  • 10
  • 17
  • great solution, is there a way to exclude all the pod files? there are a couple of Todos oder Mixmes in my used extensions? – Marco Weber May 02 '18 at 17:43
  • found a solution by myself in this post https://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/"` – Marco Weber May 15 '18 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.

Steve Moser
  • 7,647
  • 5
  • 55
  • 94
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

Leonardo Cavalcante
  • 1,274
  • 1
  • 16
  • 26
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.

aturan23
  • 4,798
  • 4
  • 28
  • 52
nenchev
  • 1,998
  • 28
  • 16
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}
Darren Ehlers
  • 633
  • 6
  • 16
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 ;)

Scoregraphic
  • 7,110
  • 4
  • 42
  • 64
drew..
  • 3,234
  • 3
  • 16
  • 19
0
#error

and

#warning

are also used in C programming

Deepraj Chowrasia
  • 1,349
  • 10
  • 20