Have Xcode open a given source file at specific line number (URL scheme?)?

306 Views Asked by At

I'm working on a custom log file viewer and would like to add a way to jump to a specific line in a source file in Xcode.

Is there a way to have Xcode reveal a given source file of the active project and jump to a given line number?

Maybe there is a custom URL scheme that I could use?

Instruments can do this (reveal a file in Xcode) so there must be a way for Instruments and Xcode to communicate.

1

There are 1 best solutions below

2
Jeehut On

I just searched for the same thing and found this discussion on the Apple forums. The gist of it is that you can use the command line tool xed that ships with Xcode like so:

xed --line 42 Path/to/your/File.swift

Running man xed gives this description of the tool:

The xed tool launches the Xcode application and opens the given documents, or opens a new untitled document, optionally with the contents of standard in.

It also mentions this option I used above:

 -l, --line <number>
          Selects the given line in the last file opened.