Can Swift playgrounds see other source files in the same project?

前端 未结 4 883
终归单人心
终归单人心 2020-12-29 02:00

I created the most simple custom class in a separate Swift file in my project:

class Foo
{
    init()
    {
        println(\"I made a foo.\")
    }
}
         


        
4条回答
  •  醉话见心
    2020-12-29 02:27

    In Xcode 10's Project Navigator:

    1. Add the source code file to the playground's Sources folder.
    2. Drag the file from the playground's Sources folder to the desired location in the project (you should see the little "plus in a circle" icon appear.
    3. End the drag and then in the Add File dialog uncheck "copy if needed"

    The source file now "lives" in the playground package; the Project refers to it (you can verify that with the File Inspector).

    I tried it the other way around: file lives in project folder with reference in playground's Sources folder but it didn't work; I ended up with two copies of the source code file.

提交回复
热议问题