Swift REPL History

How do I get the Swift REPL history to work like any other REPL history?

Currently if I press the up key I get the first item on all the history instead of the latest, then I have keep scrolling down until I get to the result I want.

1 Like

Relevant bug report

1 Like

Another related bug report:

And some more related threads.

It seems like the REPL doesn't get very much attention. It's been really broken for more than a year (and I mean basic functionality like history and code completion, on macOS), so it's almost unusable, which is a pity. I used it quite a lot before it was this broken.


Does anyone know if Swift's REPL has been abandoned?
Is it as broken as it is for me for everyone?
Will it ever be fixed?

It's not just history and code completion that is broken, you can't type or paste special characters, and it has its own special way of printing:

$ swift
Welcome to Apple Swift version 5.1.3 (swiftlang-1100.0.282.1 clang-1100.0.33.15).
Type :help for assistance.

  1> let x = 1.2
x: Double = 1.2

  2> let y = 1.1
y: Double = 1.1000000000000001   <---. I know there are reasons for this, 
  3> print(y)                        | but it still isn't particularly
1.1       <--------------------------' nice or useful.

  4> let b: UInt8? = 214   <---------.
b: UInt8? = -42        <-------------' No REPL, it's *unsigned* …
  5> b!
$R0: UInt8 = 214
  6> print(b)

  7> "\U+FFC3\U+FFA5\U+FFC3\U+FFA4\U+FFC3\U+FFB6"  <-- Me trying to type
$R1: String = ""                                       "åäö" which works
                                                        fine in Terminal.

Note that apart from it not being able to show åäö, those aren't even valid Swift escape sequences, the correct format would be:


But that is not "åäö", it's:


It says   Welcome to Apple Swift version 5.1.3,   but I don't feel very welcomed at all. :slightly_frowning_face:


It is broken for me as well. I run into all the issues you describe. It often crashes on tab completion. Scrolling through history is odd. If I want to use any special characters (maybe I want to put my mean in a µ) it doesn't work right.

This feels like a shame because all of it used to work correctly. swift run --repl was such a step forward in convenience when it came out. You could just spin up a REPL and run your calculations (or whatever else) right there on the prompt. Much lighter weight than a playground or the initial setup for Jupyter.


Yes, I've had to switch from Swift REPL to Python for doing quick calculations etc.


I've just downloaded the latest development snapshot and this seems to be the current state:

$ xcrun --toolchain swift swift --version
Apple Swift version 5.2-dev (LLVM c4dc5e9a4f, Swift a09b6418a0)
Target: x86_64-apple-darwin19.2.0
$ xcrun --toolchain swift swift
error: failed to launch REPL process: process exited with status -1 (Error 1)

Yes, when Swift was announced with the REPL, I though "that's great, I will use it instead on the Python one, for quick calculations and trying out new APIs".

But each time I start the REPL it is totally broken, or the autocomplete feature crashes the REPL or the history is unusable. Each time I think, this is an obvious and huge bug it will probably be fixed by the next release, but nope.

I really hope that fixing the REPL and making it quick and good is part of the point #2: Create a fantastic development experience of @tkremenek Swift 6 manifesto.


Isn't this up to the "community" to fix since the whole thing is open source? Can some well endowed entities/persons fund "Swift Bug Bounty".

Seems like code completion and history is working now with Xcode 11.4 (11E146). I've just done a very quick test on macOS.


Yes, for me too, great! I hope this time it keeps working in the next releases :smiley:

1 Like

Just want to chime in and say it's working for me as well. Using Unicode characters works again as well.

I'm back to happily doing calculations in a swift run --repl. Thanks so much for the fixes here!

1 Like

I can't reproduce this on my macOS system. Can you provide a little detail about where you're seeing this (and/or if it's been fixed?)

That was before I updated to Xcode 11.4 (via App Store update), and it seems to be fixed in 11.4.
Those errors was with the REPL of the previous Xcode GM, Swift version 5.1.3.

1 Like

I just bumped into this similar issue with the most recent (otherwise greatly improved) REPL though:

$ swift
Welcome to Apple Swift version 5.2 (swiftlang-1103.0.32.1 clang-1103.0.32.29).
Type :help for assistance.
  1> UInt8(214)
$R0: UInt8 = 214
  2> (UInt8(214))
$R1: (UInt8) = {
  _value = -42

Ugh, thanks for reporting. I think that this is fixed on master, but I'll follow-up with the team.