42

I have started to use the FIXME, TODO, ??? and !!! tags in XCode but have am finding it painful that it does not recognise the tags when they are within a function. The tags are only recognised outside a given function.

How can I get these tags recognised within a function (as this is where the bugs are)?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Ben
  • 836
  • 1
  • 9
  • 19
  • 1
    Maybe it's because I'm still on Xcode 3.2.6, but those show up fine in the list of functions ... are you looking for some kind of indentation to show membership in the function? – Richard May 05 '11 at 00:25
  • 1
    Could you please indicate what version of Xcode you're on and (if not Obj-C) what language you're writing in? – jscs May 05 '11 at 01:22
  • I'd recommend filing a bug report with Apple requesting this feature if you haven't already: http://bugreport.apple.com – Stuart M May 05 '11 at 08:44
  • 4
    This is a known issue and is under consideration in bug: Bug ID# 7604687 – Ben May 10 '11 at 18:31
  • 1
    This is still not fixed in 4.3, I don't think they care much – Aram Kocharyan Feb 25 '12 at 07:02
  • A friend of a friend told me that this issue is fixed in the 4.4 developer preview. – Matthias Bauch Apr 25 '12 at 18:15
  • Well, seems the implementation is very unstable. Got it to work perfectly the first and second time, when I tried all these tags to reply your question, but the third time and beyond it didn't work. – Johan Jul 12 '12 at 08:12
  • Related: http://stackoverflow.com/questions/16913055/how-to-mark-to-do-comments-in-xcode – Steve Melnikoff May 20 '15 at 16:58

9 Answers9

51

In xcode 4.1 (don't know if this works in previous versions) I write

#warning TODO: fix this later...

to get a compile warning or

#error FIXME: fix now!

to get a compile error.

I also add these to the code snippet library to make it really ease to add todos.

loomer
  • 2,017
  • 1
  • 17
  • 11
37

A workaround is to use a build script which marks those as warnings:

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

Credit to Benjamin Ragheb.

fabb
  • 11,660
  • 13
  • 67
  • 111
frank
  • 597
  • 4
  • 7
  • 11
    the script is found [here](http://www.benzado.com/blog/post/329/make-xcode-nag-you-about-unfinished-todos) by Benjamin Ragheb – KDaker Aug 27 '11 at 14:58
  • 3
    this script fails if your code is stored in a file path which contains directories with spaces in them. For example "/Home/John/iPhone Apps/Code". Simple fix, on the second line, put quotes around ${SRCROOT} – john Oct 21 '11 at 03:20
  • I put this in a run script in Xcode but somehow it's not picking up any of my TODOs. Any idea why – Raffi Khatchadourian Jan 16 '12 at 07:24
  • Combine this with a project template: http://stackoverflow.com/questions/5550958/how-to-add-a-build-phase-in-a-project-template – basvk Apr 26 '13 at 06:38
  • 1
    second line should be changed in order to support .swift files: `find "${SRCROOT}" \( -name "*.h" -or -name "*.m" -or -name "*.swift" \) -print0 | \ ` – art-divin Jan 24 '15 at 15:31
  • If you want to exclude Carthage components you can use : find "${SRCROOT}" \( -name "*.swift" \) -not -path "${SRCROOT}/Carthage/*" -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($TAGS).*\$" | perl -p -e "s/($TAGS)/ warning: \$1/" – HixField Apr 23 '18 at 09:21
20

Edited 2016-02-02

Xcode now supports //MARK:, //TODO: and //FIXME: landmarks to annotate your code and lists them in the jump bar.


To find those special markups (and actually any markups you specify yourself), you can use the search navigator, enter the following string and then choose "In Project, matching regex "...", ignore case":

(//FIXME|//!!!|//\?\?\?|//TODO)

This will search your project for all those special markups. You can even add any markup you would like to, e.g. "//REVIEW: please review the following code". This would then be the following search string:

(//FIXME|//!!!|//\?\?\?|//TODO|//REVIEW)

I created a tab in my workspace which has the search navigator always open, filled with this string. Unfortunately, XCode will sometimes remove this string from the searchbox, so you have to have it copy&paste ready whenever you need it.

Ramis
  • 13,985
  • 7
  • 81
  • 100
Florian
  • 501
  • 4
  • 7
8

The FIXME:, TODO:, ???: and !!!: works in 4.3.3 inside and outside of functions.

You can have any number of whitespace before or after the double slash, but you have to use uppercase and follow the tag with a colon.

Just to make it clear - all of these work:

//          FIXME: This works.
  //TODO: This works.
    //                  !!!: Working.
// // //???: Works as well.
Johan
  • 2,472
  • 1
  • 23
  • 25
4

how about this Xcode plugin? --> https://github.com/trawor/XToDo

Travis Worm
  • 166
  • 8
  • It's ok, it crashed on me a few times in XCode 5.0.2. You have to create the plug-in folder manually in XCode 5 if you don't already have one. It's very basic, it creates a list of the 4 default markers: TODO, FIXME, ??? & !!! and puts anything marked with those, into a drop down list in a separate XCode window: however, I'd like to be able to create my own markers, like "BOOKMARK:" and "WATCH:" and have them show up too - no simple way to do that with the plugin. – OverToasty Jan 18 '14 at 20:45
  • @OverToasty check out the new commit, forks make some great changes – Travis Worm Feb 12 '14 at 08:00
4

xCode 6 beta 4 should support MARK, TODO and FIXME landmarks.

Xcode now supports //MARK:, //TODO: and //FIXME landmarks to annotate your code and lists them in the jump bar. (14768427)!

Ramis
  • 13,985
  • 7
  • 81
  • 100
2

Just a heads up, but I've noticed the TODO:'s do not work within blocks of any kind. Just move it right above or below your block.

Yarmoshy
  • 79
  • 5
0

This is the script I use as an added build phase, note it excludes files pulled-in via Carthage (very annoying to get these as well otherwise since its not 'your' code) :

TAGS="WARNING:|TODO:"
echo "searching ${SRCROOT} for ${TAGS}"
find "${SRCROOT}" \( -name "*.swift" \) -not -path "${SRCROOT}/Carthage/*" -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($TAGS).*\$" | perl -p -e "s/($TAGS)/ warning: \$1/"

Works well on xCode 9.3 with Swift 4

HixField
  • 3,538
  • 1
  • 28
  • 54
0

If you want to continue developing but need to ensure your app doesn't get released with a leftover //FIXME: you can do the following as an alternative.

Define this somewhere in one of your headers:

#if DEBUG
#define FIXME 0;
#endif

This definition lets your app build for debug but prevents it from being archived for release.

Now you can use FIXME anywhere you would've used the comment.

Ex: NSNumber *magicNumber = 7; FIXME

lundhjem
  • 608
  • 6
  • 12