63

I couldn't find a way to put a bookmark inside the code in XCode 4. I know about the #pragma mark thing but it's not what I'm looking for. What I need is something that I can put and remove with a mouse click and navigate amongst with next and previous, like in VS.

Is there anything that I'm missing?

aslı
  • 8,740
  • 10
  • 59
  • 80

8 Answers8

61

2023 Update

Xcode 15 has a new Bookmark Navigator and associated bookmark features including task-like management and inline source annotations!

Old Answer

Bookmarks seem to have gone the way of the dinosaur in Xcode 4. This wouldn't have been so bad had the jump-to-bookmark popup above the editor in previous versions not also disappeared. The best replacement currently seems to be to use breakpoints (disabled individually, of course) and navigate with the Breakpoint Navigator.

Shortcut to breakpoints is Cmd + 8. Once there use arrow keys

File a bug report at http://bugreporter.apple.com if you feel something like this should be brought back.

Joshua Nozzi
  • 60,946
  • 14
  • 140
  • 135
  • 1
    yeah, I'm navigating with Breakpoint Navigator. Thx for the answer, I'll file a report then. – aslı Mar 29 '11 at 13:59
59

Write below comment in your source file that you want bookmarked.

 //<##>

And you can navigate to next / previous with: '^/' or '^?'

  1. <##> means "placeholder of code snippet"
  2. ^/ means "jump to next placeholder"
  3. ^? means "jump to previous placeholder"

thanks

steve kim
  • 641
  • 5
  • 10
18

Another option, if anyone is still interested. The following directives will both produce a compiler warning that you can use as a bookmark:

#pragma message "<# message #>"

or

#warning <# message #>

If you want to place bookmarks using your mouse: create a code snippet with one of the 2 directives above. Drag & drop it to the line in your source file that you want bookmarked.

Navigate to next/previous with: Cmd-' and Cmd-Shift-'

octy
  • 6,525
  • 1
  • 28
  • 38
  • 1
    I wouldnt use the warning because I tell my compiler to treat warnings as errors, but the message may be useful yeah :) – aslı Jan 21 '12 at 15:53
10

In Xcode 4.4, if you leave a comment with this format:

// TODO: Your text here

it will be added as a listing in the jump bar alongside the list of methods in your current file, and then you can jump straight to that comment from that menu.

Tim R.
  • 1,570
  • 2
  • 15
  • 33
4

The simplest technique is to use a comment prepended by // TODO and then search, which allows you to jump through the issues from the navigator. Pretty hard to beat that technique.

I personally don't like using break points for bookmarks because it is not easy to enter notes. I use breakpoints as breakpoints, and prefer not to mix them up with bookmarks.

Anyhow, if you want to get a bit fancier you could get xcode to generate warnings // TODO: some message or // FIXME: some message that can be navigated in the issue navigator. I took the instructions below from this site:

Instructions

Head over to your project's item in the Project Navigator (usually at the very top) Find your target in the list of targets on the left, select it Head over to the "Build Phases" tab. Click the "Add Build Phase" in the bottom right of this screen. In the editor that appears insert the bash script shown below. Now just build and you'll see all your //TODO: and //FIXME: comments have become warnings. I love this technique, it might not be right for everyone, but hope it helps someone. Bash Script For "Run Script" Build Phase

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/" You'll also be able to click on each of the warnings in the issue navigator to go right to the file and point in your code where you left the original //TODO: or //FIXME: Extra pro tip: Make sure you're using phrases to describe your //TODO: comments like //TODO: Handle this error gracefully, and things like that. The phrases will show up in the issues list beside each warning. Credit for the little tidbit should go to "Tim" on the Cocos2D forums, (found after Googling for a bit), I believe his solution originally was intended for Xcode 3 and didn't work if you had spaces in your path name, my script here doesn't have those restrictions, still he should get full credit here's his original post.

SmileBot
  • 19,393
  • 7
  • 65
  • 62
  • 1
    I up-voted this because it's another workable solution but I don't personally like it because it requires you to modify actual source. A is a temporary thing for quick navigation that may survive a few code commits. My OCD doesn't allow it even on a single-developer project; how do you think a team environment would like everybody's bookmarks showing up in the repository? ;-) Apple *really* needs to add a navigation-only bookmarks feature that doesn't modify code (just like breakpoints). – Joshua Nozzi Nov 04 '14 at 16:46
2

My method:

type in grammar error code in the previous line.....

After changing something in other place, I can go back to the previous place because the grammer error line will show a red line in the right side scroll bar. It indicate the place.

It is not elegant but unless there is a bookmark feature, this is the way i am using at the moment

elephant.lyh
  • 133
  • 1
  • 5
  • See my response to cocoanut's answer - I don't like modifying code (the changes may get checked in). However, if I'm interrupted or quitting for the day in the middle of something complicated, I often start a line with (minus the quotes) "::: // Notes about what I was doing". That way, even if the project is closed or my place is otherwise lost, the resulting error highlights the spot **and** I can refresh my memory. – Joshua Nozzi Nov 04 '14 at 16:49
2

Like npellow's answer to this question of mine, appCode by JetBrains has also made this possible. So, this may be another reason to use appCode instead of Xcode4, except that it won't be free later in time.

Community
  • 1
  • 1
aslı
  • 8,740
  • 10
  • 59
  • 80
  • 8
    If they're considering charging for it, they have a *lot* more work to do. AppCode is pretty clunky and it's a Java app that runs only on Mac OS with Intel processors. Hell, even Eclipse is free. I further question any developer that chooses Java over the native language and API to target *one* OS platform. – Joshua Nozzi May 11 '11 at 14:41
  • Why would you question? Obviously their programmer's expertise are in Java. I would imagine a lot of the internal stuff is borrowed from other IDEs from other languages on other platforms. It's not so strange when you look at it that way. – Cthutu Feb 27 '13 at 20:23
  • resharper for visual studio is unreal, if appCode gets to have the same sort of functionality as that then i'll be there – Aran Mulholland May 06 '13 at 11:56
  • appCode is becoming essential, that product is growing by leaps and bounds. I use both IDE's now, appCode has excellent refactoring tools that xCode lacks – Aran Mulholland Dec 16 '13 at 20:25
  • I too was initially dissapointed by Rubymine (another JetBrains Java product). It was slow and ate up my CPU. With version 6 they've done a wonderful job and now I can't live without it. Don't let your prejudices (like I did) keep you from using good software. I don't like Java apps **at all** but Rubymine is great. Maybe appCode will be too. – kakubei Oct 02 '14 at 09:08
  • Just downloaded AppCode and took it for another spin today. Same problems: Resource hog (including battery life on my MBP), clunky and out of place on a Mac, tries to be too generalized an IDE to be a particularly good Mac / iOS IDE, keeps wanting to open Xcode to do the stuff it can't (which is far more than I deem acceptable). I'll stick to filing enhancement requests with the Developer Tools team to improve Xcode itself. – Joshua Nozzi Feb 03 '15 at 23:12
0

You can install an Xcode plugin called "XBookmark".

This plugin provide features below :

  • Toggle Bookmark
  • Show Bookmarks
  • Next Bookmark
  • Previous Bookmark

How to install XBookmark:

  1. Install Alcatraz.
  2. Search XBookmark from Window->Package Manager and click Install.
  3. Restart Xcode.

Now, you can see menus about bookmarks in the Edit Menu.

PS : This plugin is open source.

everettjf
  • 126
  • 9