//加載plist數據
// 一個NSBundle對象對應一個資源包(圖片、音頻、視頻、plis等文件)
// NSBundle的作用:用來訪問與之對應的資源包內部的文件,可以用來獲得文件的全路徑
// 項目中添加的資源都會被添加到主資源包中
// [NSBundle mainBundle]關聯的就是項目的主資源包
NSBundle *bundle = [NSBundle mainBundle];
// 利用mainBundle獲得plist文件在主資源包中的全路徑
NSString *file = [bundle pathForResource:@"shops" ofType:@"plist"];
// NSString *file = [bundle pathForResource:@"shops.plist" ofType:nil];
// 凡是參數名爲File,傳遞的都是文件的全路徑
self.shops = [NSArray arrayWithContentsOfFile:file];
懶加載
// 加載plist數據(比較大)
// 懶加載:用到時再去加載,而且也只加載一次
-(NSArray *)shops
{
if (_shops == nil) {
// 加載plist數據
// 一個NSBundle對象對應一個資源包(圖片、音頻、視頻、plis等文件)
// NSBundle的作用:用來訪問與之對應的資源包內部的文件,可以用來獲得文件的全路徑
// 項目中添加的資源都會被添加到主資源包中
// [NSBundle mainBundle]關聯的就是項目的主資源包
NSBundle *bundle = [NSBundle mainBundle];
// 利用mainBundle獲得plist文件在主資源包中的全路徑
NSString *file = [bundle pathForResource:@"shops" ofType:@"plist"];
// NSString *file = [bundle pathForResource:@"shops.plist" ofType:nil];
// 凡是參數名爲File,傳遞的都是文件的全路徑
_shops = [NSArray arrayWithContentsOfFile:file];
NSLog(@"dasdsa");
}
return _shops;
}