NSBundle pathForResource: ofType: sometimes returns zero for one resource

Usually, when you try to load a specific resource in my application via [[NSBundle mainBundle] pathForResource:@"iphone" ofType:@"splang"] , it works fine, but nil returns every time. The iphone.splang file in question is a ~ 275KB text file that is definitely associated with the application (as evidenced by its ability to download).

I checked that this is pathForResource: ofType: returns nil, not the mainBundle method.

+4
source share
1 answer

This may be a problem of internationalization. According to the documentation , pathForResource returns only zero if the file is not found. But he also says:

First, the method searches for the corresponding resource file in the non-localized resource directory of the specified package. [...] If the corresponding resource file is not found, it will be displayed at the top level of any available ".lproj" directories for a particular language. (The search order for language directories matches user preferences.) It does not recurs through other subdirectories at any of these locations.

Perhaps you are trying to use your code on different machines with different languages ​​or a simulator.

In addition, [NSBundle mainbundle] can return nil, so making any call on this also returns nil.

[...] Be sure to check the return value to make sure you have a valid package.

+1
source

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


All Articles