Xcode 15 added a new way to bookmark source code annotations and search queries.
Bookmarking Code
Xcode has long had support for TODO and other annotations in source code:
// TODO: Migrate to Observable
public final class Store: ObservableObject {
// MARK: Published properties
@Published public var items: [Int] = []
}
Xcode shows these annotations in the selection toolbar but I think I gave up using them when I stopped writing Objective-C.
Xcode 15 introduced a new way to bookmark and annotate source code. With a line of source code selected, the context menu (control-click or right-click in the source editor) has options to bookmark the line or the whole file:
Xcode shows the bookmarks in the third tab of the navigators sidebar. This replaces the old symbol navigator whose functionality Xcode now supports directly in the Find navigator. Clicking the bookmark takes you to the line of code in the source editor:
The Xcode source editor adds a bookmark icon, clicking it lets you to add a description:
Xcode shows the description in the bookmark navigator:
Right-clicking on the bookmark in the navigator gives you options to edit, copy, and delete bookmarks.
Grouping Bookmarks
The Xcode bookmark navigator allows you to create groups to organise your bookmarks. For example, I’ve created a group for my TODO bookmarks:
Note: Right-clicking on the group gives you options to sort the contents of the group by name, type, or completion status.
Marking Complete
You can mark any bookmark as complete. The bookmark navigator shows completed bookmarks with a tick:
Bookmarking Search Queries
Xcode also lets you bookmark search queries. For example, here’s a query to find all the places where I’ve added TODO annotations directly to the source code:
Right-clicking anywhere in the search results, I can bookmark the search. Xcode then shows that saved search in the bookmarks navigator where I can move it to my TODO group:
I’m not sure why, but Xcode includes a couple of example queries for SwiftUI views and SwiftData models in the navigator menu buried down next to the filter:
Note: The menu shows those two searches regardless of whether the project uses SwiftUI or SwiftData.
Clicking either option from the menu adds a saved search to the bookmark navigator to find any SwiftUI views or SwiftData models:
I’m finding bookmarks to be an improvement over directly annotation source code. Let me know how you’re using them.