Search code examples
iosrubymotion

happens not to target resources in a folder with fileURLWithPath


I have a concern with this method :

NSURL.fileURLWithPath (NSBundle.mainBundle.bundlePath)

until the the works well but I would like to resouces that my method looks for me in the pages folder.

I did something like this:

NSURL.fileURLWithPath (NSBundle.mainBundle.bundlePath + 'page/')

but its not working, therefore I do not see how I could use it.

Thank you.


Solution

  • Use this NSBundle method

    URLForResource:withExtension:subdirectory:
    

    Returns the file URL for the resource file identified by the specified name and extension and residing in a given bundle directory.

    • (NSURL *)URLForResource:(NSString *)name withExtension:(NSString *)extension subdirectory:(NSString *)subpath

    or any other in NSBundle, there are method for returning array of URLs in subdirectory of you want to iterate them for example.