//
// ViewController.m
// UI08_KVC
//
// Created by lanou3g on 17/8/14.
// Copyright © 2017年 lanou3g. All rights reserved.
//
#import "ViewController.h"
#import "Song.h"
@interface ViewController ()
@property (nonatomic,retain) NSMutableArray *songArray;
@end
@implementation ViewController
- (void)getData {
self.songArray = [NSMutableArray array];
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"SongList" ofType:@"plist"];
NSArray *songList = [NSArray arrayWithContentsOfFile:filePath];
for (NSDictionary *songDic in songList) {
Song *song = [[Song alloc] init];
// song.title = songDic[@"title"];
// song.author = songDic[@"author"];
// song.album_titile = songDic[@"album_titile"];
[song setValuesForKeysWithDictionary:songDic];
[self.songArray addObject:song];
}
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self getData];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
//
// Song.h
// UI08_KVC
//
// Created by lanou3g on 17/8/14.
// Copyright © 2017年 lanou3g. All rights reserved.
//
#import
@interface Song : NSObject
@property (nonatomic,retain) NSString *title;
@property (nonatomic,retain) NSString *author;
@property (nonatomic,retain) NSString *album_titile;
@end
//
// Song.m
// UI08_KVC
//
// Created by lanou3g on 17/8/14.
// Copyright © 2017年 lanou3g. All rights reserved.
//
#import "Song.h"
@implementation Song
//系统检测不到有对应的成员变量可以和字典中的key对应,调用此方法
- (void)setValue:(id)value forUndefinedKey:(NSString *)key {
NSLog(@"%@",key);
//如果将来字典中的key和系统关键字重名,我们在model中定义属性名会起和key不一样的名字,然后在这个方法里做一个对应
// if (key isEqualToString:@"id") {
// _songId = value;
// }
}
//系统检测到有对应的成员变量可以和字典中的key对应,调用此方法
//- (void)setValue:(id)value forKey:(NSString *)key {
// if ([key isEqualToString:@"cityArray"]) {
// for (NSDictionary *cityDic in value) {
// City *city = [[City alloc] init];
// [city ]
// }
// }
//}
@end