Search code examples
iosrubymotion

How do I access files from the resources folder in my RubyMotion code?


I have some data files in the resources/ folder for my Rubymotion project. How do I access them in the code? Accessing them without a path, is not working.

e.g. I have a file in resources/ called schema.json

Here's the code I am using:

NSData.dataWithContentsOfFile("schema.json") <--- returns nil

Solution

  • Figured it out.

    path = NSBundle.mainBundle.pathForResource("schema", ofType:"json")
    NSData.dataWithContentsOfFile(path)