Often see a similar
NSString *file = [[NSBundle mainbundle] Pathforresource:name Oftype:nil];
This code is used to get the full path of file.
Then what is it: First look at the NSBundle class, directly inherit the NSObject class.
The object of this class, which represents the location of the files of the Code and resources in the app in the file system, is the location of the resources (code, graphics, music, etc.) that the program uses, and the executable code can be loaded dynamically or unloaded.
Our program is a bundle. In the Finder, an application looks no different from other files. But it's actually a directory that contains nib files, compiled code, and other resources. We call this directory the program's main bundle, in Xcode, when using the application, framework, or plugin, Xcode generates the corresponding resource's directory package.
Class method:
Mainbundle Method Detailed
+ (NSBundle *) mainbundle
Returns an object of the NSBundle class that is an entirely path, the path of the currently executable app that the path holds, or nil returned. After the app, build, the resource file is copied directly to the root directory, so the method of reading should be:
NSString *earth = [[NSBundle mainbundle] pathforresource:@ "Brad Cox" oftype:@ "PNG"];
After compiling, Mainbundle's resources are placed under RootFolder, so you can access them directly and don't specify internal paths. Typically, this mainbundle is the absolute path of the current executable app under the root directory,
That is
The Name+.app suffix of the path +app where the Finder root begins. Resources are accessed directly, in the app's package. such as
/users/dashuai/library/application Support/iphone simulator/9.1/applications/ 3b8ec78a-5eee-4c2f-b0cb-4c3f02b996d2/tomcat.app/drink.png
An understanding of IOS NSBundle and an explanation of Mainbundle methods