Ankit Goel Ankit Goel - 1 year ago 69
Swift Question

How do I quit swift repl without using ctrl-d?

I want to quit swift repl gracefully and not use ctrl-d to exit it.

For eg. python repl can be exited by typing

. Is there a similar way of quitting swift repl?

Answer Source

Swift REPL works in conjuction with the LLDB debugger.

: is a REPL escape prefix to execute an LLDB command. From within REPL, :help will list the available LLDB commands.

Any of the following will quit both Swift REPL and subsequently LLDB with a single command line.


One can also exit REPL into LLDB with just : and, then later quit (or exit) using the LLDB command directly.

sh$ swift
1> print(18 + 4)
2> :
(lldb) print "hello"
  (String) $R0 = "hello"
(lldb) quit

Addendum: The LLDB command c or continue can be used to return to the Swift REPL environment.