This question already has an answer here:
这个问题在这里已有答案:
- Swift REPL: how to import, load, evaluate, or require a .swift file? 5 answers
- Swift REPL:如何导入,加载,评估或需要.swift文件? 5个答案
- How to include .swift file from other .swift file in an immediate mode? 2 answers
- 如何在立即模式下包含来自其他.swift文件的.swift文件? 2个答案
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