标签:
------------- CZQuestion.h -------------
#import <Foundation/Foundation.h>
@interface CZQuestion : NSObject
@property (nonatomic, copy) NSString *answer;
@property (nonatomic, copy) NSString *icon;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, strong) NSArray *options;
- (instancetype)initWithDic:(NSDictionary *)dic;
+ (instancetype)questionWithDic:(NSDictionary *)dic;
+ (NSArray *)questionsList;
@end
------------- CZQuestion.m -------------
#import "CZQuestion.h"
@interface CZQuestion ()
@end
@implementation CZQuestion
- (instancetype)initWithDic:(NSDictionary *)dic
{
if (self = [super init])
{
[self setValuesForKeysWithDictionary:dic];
}
return self;
}
+ (instancetype)questionWithDic:(NSDictionary *)dic
{
return [[self alloc] initWithDic:dic];
}
+ (NSArray *)questionsList
{
NSBundle *bundle = [NSBundle mainBundle];
NSString *path = [bundle pathForResource:@"questions" ofType:@"plist"];
NSArray *dicArray = [NSArray arrayWithContentsOfFile:path];
NSMutableArray *tmpArray = [NSMutableArray array];
for (NSDictionary *dic in dicArray)
{
CZQuestion *question = [[CZQuestion alloc] init];
question.answer = dic[@"answer"];
question.icon = dic[@"icon"];
question.title = dic[@"title"];
question.options = dic[@"options"];
[tmpArray addObject:question];
}
return tmpArray;
}
@end
标签:
原文地址:http://www.cnblogs.com/lixiang2015/p/4708909.html