zoukankan      html  css  js  c++  java
  • QQ好友列表数据模型封装

    QQ好友中的信息较多。假设我们单独从plist 中直接取出数据 是能够解决这个问题 

    可是相当复杂。以为列表中分组 。每组中还有不同信息 

    大致模型是 数组套数组  数组套字典 

    所以我们要封装数据模型

    //
    //  GPGroupController.h
    //  02-好友分组
    //
    
    
    #import <UIKit/UIKit.h>
    
    @interface GPGroupController : UIViewController
    
    @end
    

    //
    //  GPGroupController.m
    //  02-好友分组
    //
    
    
    #import "GPGroupController.h"
    #import "GPGroup.h"
    #import "NSArray+LocalPrint.h"
    @interface GPGroupController ()
    
    @property(nonatomic,strong)NSArray *groups;
    
    @end
    
    @implementation GPGroupController
    
    -(NSArray *)groups
    {
        if (_groups == nil) {
            //1.
            NSString *path = [[NSBundle mainBundle]pathForResource:@"qq_group.plist" ofType:nil];
            NSArray * dicts =[NSArray arrayWithContentsOfFile:path];
            
            //2.
            NSMutableArray *objs = [NSMutableArray array];
            for(NSDictionary *dic in dicts)
            {
                GPGroup *group = [GPGroup groupWthDict:dic];
                [objs addObject:group];
            }
            //3.
            _groups = objs;
        }
        return _groups;
    }
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        NSLog(@"%@",self.groups);
        // Do any additional setup after loading the view.
    }
    
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    /*
    #pragma mark - Navigation
    
    // In a storyboard-based application, you will often want to do a little preparation before navigation
    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
        // Get the new view controller using [segue destinationViewController].
        // Pass the selected object to the new view controller.
    }
    */
    
    @end
    

    //
    //  GPFriend.h
    //  02-好友分组
    
    #import <Foundation/Foundation.h>
    
    @interface GPFriend : NSObject
    @property(nonatomic,copy)NSString *icon;
    @property(nonatomic,copy)NSString *message;
    @property(nonatomic,copy)NSString *name;
    
    +(id)friendWithDict:(NSDictionary *)dict;
    -(id)initWithDict:(NSDictionary *)dict;
    @end
    

    //
    //  GPFriend.m
    //  02-好友分组
    //
    
    #import "GPFriend.h"
    
    @implementation GPFriend
    +(id)friendWithDict:(NSDictionary *)dict
    {
        return [[self alloc]initWithDict:dict];
    }
    -(id)initWithDict:(NSDictionary *)dict
    {
        if (self = [super init]) {
            [self setValuesForKeysWithDictionary:dict];
        }
        return self;
    }
    
    - (NSString *)description
    {
        return [NSString stringWithFormat:@"icon=%@,name=%@,message=%@", _icon,_name,_message];
    }
    @end
    


  • 相关阅读:
    [WSUS] Windows Server Update Service 更新后,出现错误不能连接
    [SQLServer] 数据库SA用户被锁定或者忘记密码的恢复
    [SQLServer] 内存占用查看
    [IIS] [PHP] 500.19 随机出现
    [OPENSSL下载][证书] OPENSSL将PFX证书转换为PEM格式
    [VS2015] [asp.net] 允许远程访问本机正在DEBUG的服务
    [VS2008] 安装 AnkhSVN 后,选项中选择它,Pending Changes 窗口一闪而过,源代码管理工具自动跳回 【None】
    [IIS] 配置PHP的过程与坑
    10分钟快速入门vue.js
    前端接口请求的几种方式
  • 原文地址:https://www.cnblogs.com/clnchanpin/p/6918751.html
Copyright © 2011-2022 走看看