zoukankan      html  css  js  c++  java
  • 字典转模型规范化

    //

    //  MJApp.h

    //  01-应用管理

    //

    //  Created by apple on 14-3-26.

    //  Copyright (c) 2014年 itcast. All rights reserved.

    //  模型类:用来存放数据的类

    #import <Foundation/Foundation.h>

    /**

     copy : NSString

     strong: 一般对象

     weak: UI控件

     assign:基本数据类型

     */

    @interface MJApp : NSObject

    /**

     *  名称

     */

    @property (nonatomic, copy) NSString *name;

    /**

     *  图标

     */

    @property (nonatomic, copy) NSString *icon;

    /**

     *  通过字典来初始化模型对象

     *

     *  @param dict 字典对象

     *

     *  @return 已经初始化完毕的模型对象

     */

    - (instancetype)initWithDict:(NSDictionary *)dict;

     

    + (instancetype)appWithDict:(NSDictionary *)dict;

    @end

    //

    //  MJApp.m

    //  01-应用管理

    //

    //  Created by apple on 14-3-26.

    //  Copyright (c) 2014年 itcast. All rights reserved.

    //

    #import "MJApp.h"

    @implementation MJApp

    - (instancetype)initWithDict:(NSDictionary *)dict

    {

        if (self = [super init]) {

            self.name = dict[@"name"];

            self.icon = dict[@"icon"];

        }

        return self;

    }

    + (instancetype)appWithDict:(NSDictionary *)dict

    {

        return [[self alloc] initWithDict:dict];

    }

    @end

  • 相关阅读:
    产品方法论
    elastic search语句
    计算机科学发展的动力
    理论计算机科学学习网站
    算法学习 howto
    人工智能和机器学习 AI&ML howto
    Deep Learning 和 Knowledge Graph howto
    LISP语言学习资源
    Turing Year 2012
    如何做好计算机科学研究
  • 原文地址:https://www.cnblogs.com/supper-Ho/p/6207979.html
Copyright © 2011-2022 走看看