Swift REPL:如何导入,加载,评估或需要.swift文件? [英] Swift REPL: how to import, load, evaluate, or require a .swift file?

查看:114
本文介绍了Swift REPL:如何导入,加载,评估或需要.swift文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Swift REPL中,如何导入(也就是加载,评估,要求)典型的文本* .swift文件?

In the Swift REPL, how to import (a.k.a. load, evaluate, require) a typical text *.swift file?


  • 我想使用此文件中的代码:〜/ src / Foo.swift

像这样的语法不起作用: import~ / src / Foo.swift

Syntax like this doesn't work: import ~/src/Foo.swift

用于比较:


  • 框架的Swift REPL中的等效解决方案是: import Foundation

Ruby REPL中* .ruby文件的等效解决方案是:需要〜/ src / foo

An equivalent solution in the Ruby REPL for a *.ruby file is: require "~/src/foo"

以下是类似的问题/我在问什么:

These are similar questions that are /not/ what I'm asking:


  • 如何使用/制作Swift命令行脚本,可执行文件,模块等。

  • How to use/make a Swift command-line script, executable, module, etc.

如何使用/制作XCode游乐场,项目,库,框架等

How to use/make an XCode playground, project, library, framework, etc.

如何使用预先存在的文件列表启动REPL。

How to launch the REPL with a pre-existing list of files.

推荐答案

你需要使用-I,所以如果你的modulename.swiftmodule文件在〜/ mymodules中而不是使用

You need to use -I, so if your modulename.swiftmodule file is in ~/mymodules than launch swift with

swift -I ~/mymodules

然后你就可以导入你的模块

and then you will be able to import your module

import module name

应该那么简单

这篇关于Swift REPL:如何导入,加载,评估或需要.swift文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆