//
// 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 <Foundation/Foundation.h>
@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
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。