我可以将我的项目代码导入 Swift REPL 吗? [英] Can I import my project code into the Swift REPL?

查看:24
本文介绍了我可以将我的项目代码导入 Swift REPL 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Swift REPL 很棒,但如果我可以从 Xcode 项目导入类就更好了.我尝试切换到我的项目目录并运行

The Swift REPL is great, but it would be even better if I could import the classes from an Xcode project. I tried switching to my project directory and running

$ swift
> import ProjectName

但我得到了:

error: no such module 'ProjectName'

可以这样做吗?

推荐答案

Swift REPL 包括许多不同的选项.使用 swift -help 来查看它们.对于您的情况,如果您已将 ProjectName 定义为框架目标,并且在目标中您已声明定义模块",则您可以通过以下方式访问它:

The Swift REPL includes a number of different options. Use swift -help to see them. For your case, if you've defined ProjectName as a framework target and in the target you've declared 'Defines Module' then you can access it with:

$ swift -F <install path with subdirectory ProjectName.framework>
> import ProjectName

这是一个例子:

$ swift -F /Users/.../Library/Developer/Xcode/DerivedData/Opus-bsjennhdtvmqrhejuabovdyxlqte/Build/Products/Debug/
Welcome to Swift!  Type :help for assistance.
  1> import OpusOSX
  2> version                    // var from framework
$R0: String = "Opus 1.0"
  3> any([1,3]) { 0 == $0 % 2 } // 'any()' in framework
$R1: Bool = false
  4> any([1,2,3]) { 0 == $0 % 2 } 
$R2: Bool = true
  4> any([1,2,3,4], conjoin ({ 0 == $0 % 2 }, { $0 >= 3 })) 
$R3: Bool = true

这篇关于我可以将我的项目代码导入 Swift REPL 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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