1

To localitie items in the standard directories, I have just used either one of these:

NSURL* url = [[NSBundle mainBundle] URLForResource:@"search" withExtension:@"png"]; NSString *path = [[NSBundle mainBundle] pathForResource:@"search" ofType:@"png"]; 

The output is:

url is file://localhost/Users/myName/Library/......./MyApp.app/search.png path is /Users/myName/Library/......./MyApp.app/search.png 

The difference between the two of them is the missing file://localhost.

My question is when should we use URLForResource and when we use pathForResource?

1 Answer 1

2

Most iOS methods offer you to use path or url, for example

[NSData dataWithContentsOfFile:foo] [NSData dataWithContentsOfURL:foo] 

So it doesn't really matter which one you use.

For methods that require a path you could do a conversion:

[UIImage imageWithContentsOfFile:yourFilePath] 

becomes

[UIImage imageWithContentsOfFile:[NSURL fileURLWithPath:yourFilePath]] 

You can also convert a URL to a Path

yourURL.path 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.