1. 程式人生 > >iOS -- 讀取plist表中資料到NSArray

iOS -- 讀取plist表中資料到NSArray

將下表的資料列印輸出來
這裡寫圖片描述
上程式碼

#import "ViewController.h"

@interface ViewController ()
@property (nonatomic, strong) NSArray * nameDict;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self print];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (NSArray
*)nameDict { if (!_nameDict) { NSString * path = [[NSBundle mainBundle] pathForResource:@"nameData.plist" ofType:nil]; _nameDict = [NSArray arrayWithContentsOfFile:path]; } return _nameDict; } - (void) print { for (int i = 0; i < self.nameDict.count; i++) { NSLog
(@"name:%@,age:%@",self.nameDict[i][@"name"],self.nameDict[i][@"age"]); } } @end

執行結果:
這裡寫圖片描述
完美列印。