What is NSBundle and mainBundle in Objective-C?

后端 未结 3 1539
逝去的感伤
逝去的感伤 2021-02-01 16:51

Regarding Objective-C on iOS application, I read some sample program in the Apple developer website and I found that almost all of the applications contains a word called \'NSBu

3条回答
  •  無奈伤痛
    2021-02-01 17:07

    Suppose our code is:

    NSString *myFile=[[NSBundle mainBundle]pathForResource:@"subjects" ofType:@"plist"];
    

    We create subject.plist in Xcode (File> new> new file> iOS> resource> property list) and copy it into our supporting folder.

    This is really a way of getting to files installed on the iOS device when we do not know where they are. It's a way to obtain our subject.plist file, which is a part of the internal Bundle or internal package for our application. We don't have direct access to a file system on an iOS device, so this is the way we get hold of our own assets.

提交回复
热议问题