本文摘自:
NSBundle束,是一种特定的文件类型,其中的内容遵循特定的结构。
NSBundle的一个主要作用是 获取Resources文件夹中的资源。
使用主束来获取需要的资源文件:
NSBundle *bundle = [NSBundle mainBundle];
NSString *plistPath = [bundle pathForResource:@"statedictionary" ofType:@"plist"];
或者简写成一行:
NSString *path = [[NSBundle mainBundle] pathForResource:@"sortednames" ofType:@"plist"];
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path];
例如:
// get an image from the main app bundle NSBundle *appBundle = [NSBundle mainBundle]; NSString *path = [appBundle pathForResource:@"myImage" ofType:@"png"]; UIImage *image = [[UIImage alloc]initWithContentsOfFile:path];