Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
922 views
in Technique[技术] by (71.8m points)

xcode - Can I import my project code into the Swift REPL?

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

but I got:

error: no such module 'ProjectName'

Is it possible to do this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

Here is an example:

$ 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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...