码迷,mamicode.com
首页 > 其他好文 > 详细

29.小项目:超级猜图 part2

时间:2015-08-06 20:23:40      阅读:115      评论:0      收藏:0      [点我收藏+]

标签:

------------- 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

 


29.小项目:超级猜图 part2

标签:

原文地址:http://www.cnblogs.com/lixiang2015/p/4708909.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!