How to import my own class into an Xcode 7 playground?

纵饮孤独 提交于 2019-12-11 12:15:32

问题


I know this question was asked before, but I didn't find an answer in relation to Xcode 7 and Swift 2. Many answers are just ambiguous, incorrect or outdated.

Is there a clear way to import a single class or a set of classes to a playground?


回答1:


In the Playground go to menu

View / Navigators / Show Project Navigator

and copy your class files into the Sources folder.

Your classes have to be marked public like this:

public class MyPlayGround {
    public class func sayHello() {
        print("Hello")
    }
}

The Playground will then have access to the classes:

MyPlayGround.sayHello()


来源:https://stackoverflow.com/questions/32722275/how-to-import-my-own-class-into-an-xcode-7-playground

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!