在Swift REPL中运行Swift文件[重复]

时间:2022-05-07 20:42:06

This question already has an answer here:

这个问题在这里已有答案:

In Python or Haskell I can run a file inside the REPL (e.g., in Python execfile('foo.py')). How can I do the same inside the Swift REPL. I'm not using Xcode. I know if you put #!/usr/bin/swift at the top of a file, then you can run it from the shell, but I'd like to run from the interpreter.

在Python或Haskell中,我可以在REPL中运行一个文件(例如,在Python execfile('foo.py')中)。如何在Swift REPL中做同样的事情。我没有使用Xcode。我知道如果你把#!/ usr / bin / swift放在文件的顶部,那么你可以从shell运行它,但我想从解释器运行。

1 个解决方案

#1


1  

You can't run a swift file from Swift REPL, but you can import a custom framework when running the REPL:

您无法从Swift REPL运行swift文件,但可以在运行REPL时导入自定义框架:

swift -F /path/to/ProjectName.framework

Then, import the framework:

然后,导入框架:

> import ProjectName

#1


1  

You can't run a swift file from Swift REPL, but you can import a custom framework when running the REPL:

您无法从Swift REPL运行swift文件,但可以在运行REPL时导入自定义框架:

swift -F /path/to/ProjectName.framework

Then, import the framework:

然后,导入框架:

> import ProjectName