zoukankan      html  css  js  c++  java
  • Day7

    1 kvc

    key value coding

    -(instancetype)initWithDict:(NSDictionary *)dict
    {
        self = [super init];
        if (self) {
    //        self.answer = dict[@"answer"];
    //        self.icon = dict[@"icon"];
    //        self.title = dict[@"title"];
    //        self.options = dict[@"options"];
            
    //        [self setValue:dict[@"answer"] forKeyPath:@"answer"];
    //        [self setValue:dict[@"icon"] forKeyPath:@"icon"];
    //        [self setValue:dict[@"title"] forKeyPath:@"title"];
    //        [self setValue:dict[@"options"] forKeyPath:@"options"];
            
            //kvc
            [self setValuesForKeysWithDictionary:dict];
        }
        return self;
    }
    

    2 修改description

    相当于toString()

    - (NSString *)description
    {
        //如果要在开发时,跟踪对象的明细信息,可以重写description方法
        //todo:fail
        return [NSString stringWithFormat:@"<%@: %p> {answer:%@,title:%@,icon:%@,options:%@}",[self class],self,self.answer,self.title,self.icon,self.options];
    }
    

    3 添加category类

    相当于扩展类的方法 ---》选oc file --》选category

    4 getter时候定义的私有变量

    @interface QuestionObject()
    {
        UIImage *_image;
    }
    
    
    //_image 只是一个私有变量被image使用赋值并返回
    -(UIImage *)image{
        if(!_image){
            _image = [UIImage imageNamed:self.icon];
        }
        return _image;
    }
    
    @property (nonatomic,strong,readonly) UIImage *iconImage;//public
    

      

      

  • 相关阅读:
    基于Diff机制的多个状态合并
    do_mmap解读
    Linux对用户态的动态内存管理
    我的WordPress站点
    使用Bochs学习硬件原理
    inode的若干锚
    Use sed and awk to prettify json
    IO完成端口
    如何使用iText制作中文PDF
    Font and PDF
  • 原文地址:https://www.cnblogs.com/lihaozhou/p/4363963.html
Copyright © 2011-2022 走看看