如何从RubyMotion代码中的resources文件夹访问文件?

spa*_*mat 2 ios rubymotion

我在Rubymotion项目的资源/文件夹中有一些数据文件.如何在代码中访问它们?没有路径访问它们是行不通的.

例如,我在资源中有一个文件/名为schema.json

这是我正在使用的代码:

NSData.dataWithContentsOfFile("schema.json") <--- returns nil
Run Code Online (Sandbox Code Playgroud)

spa*_*mat 6

弄清楚了.

path = NSBundle.mainBundle.pathForResource("schema", ofType:"json")
NSData.dataWithContentsOfFile(path)
Run Code Online (Sandbox Code Playgroud)