IPhone referring to resources in separate directories

This question talks about how you can create directories in your resource path. Once created, how does one refer to these directories?

I created an html directory with a structure for my inner pages, now I want to download the index.html file from the html directory. So, I need a file path.

I can just use:

NSString *filename = [[NSBundle mainBundle] pathForResource:@"index" 
                                                     ofType:@"html"];

But what happens if there are two index.html files contained in the directory structure? Does he just find the first? Could the link be more specific?

A little test project here that doesn't work if you want to take a look

+3
source share
1 answer

If you have a path that is copied to your resource, you also need to specify the path when searching for the resource, for example:

NSString *filename = [[NSBundle mainBundle] pathForResource:@"html/index" ofType:@"html"];

EDIT:

Apparently, you just can't include the directory in the resource name (I suppose you can use other similar calls like "imageNamed:" in UIImage). Work call:

NSString *helpFile = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:@"html"];
+1
source

Source: https://habr.com/ru/post/1733432/


All Articles