Skip to content

Command line Swift

Ken Harris edited this page Sep 2, 2020 · 2 revisions

You can run Swift at the command line. It sort of works, but don't expect too much. It's the worst repl you've used in 25 years.

  • Do not press the "tab" key! It will probably crash. The latest instance (as of Xcode 11.3.1 / Swift 5.1.3) looks like SR-11578 but it seems every time they fix it, it just gets broken again a few months later.

  • When you see a value printed on screen, that is not its .description. Many instances, of course, don't even have a description. But even when an instance has one, that's not what it prints. It's some special LLVM value which may or may not be similar (or useful).

    URL is especially crazy:

    • It printed "file://" URLs as "ile://" until Swift 5.1.something.
    • URL(string: "\n") is URL? = nil. URL(string: "http://") is something that prints as URL? = nil too but is not that nil. So you have to check == nil separately. (SR-11593)
Clone this wiki locally