QQ Friends List Data Model encapsulation

Source: Internet
Author: User

QQ Friends in more information, if we separate from the plist directly remove the data is to solve the problem

But it's quite complicated to think of groups in the list, with different information in each group.

The approximate model is a set of arrays of array array arrays dictionary

So we're going to encapsulate the data model

  gpgroupcontroller.h//  02-Friends Group//#import <UIKit/UIKit.h> @interface Gpgroupcontroller: Uiviewcontroller@end

gpgroupcontroller.m//02-Friends Group//#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 the can be recreated.} /* #pragma mark-navigation//in a storyboard-based application, you'll often want to do a little preparation before navigation-(void) preparefor Segue: (uistoryboardsegue *) Segue sender: (ID) Sender {//Get the new view controller using [Segue Destinationviewcontrol    Ler]. Pass the selected object to the new view Controller.} */@end

  gpfriend.h//  02-Friends Group #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-Friends Group//#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


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

QQ Buddy list data Model encapsulation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.