48.小项目:QQ好友列表 M部分
---------- CZFriend.h ----------
#import <Foundation/Foundation.h>
@interface CZFriend : NSObject
@property (copy, nonatomic) NSString *icon;
@property (copy, nonatomic) NSString *intro;
@property (copy, nonatomic) NSString *name;
@property (assign, nonatomic) BOOL vip;
+ (instancetype)friendWithDict:(NSDictionary *)dict;
- (instancetype)initWithDict:(NSDictionary *)dict;
@end
---------- CZFriend.m ----------
#import "CZFriend.h"
@implementation CZFriend
+ (instancetype)friendWithDict:(NSDictionary *)dict
{
return [[self alloc] initWithDict:dict];
}
- (instancetype)initWithDict:(NSDictionary *)dict
{
if (self = [super init])
{
[self setValuesForKeysWithDictionary:dict];
}
return self;
}
@end
---------- CZFriendGroup.h ----------
#import <Foundation/Foundation.h>
@interface CZFriendGroup : NSObject
@property (copy, nonatomic) NSString *name;
@property (assign, nonatomic) int online;
@property (strong, nonatomic) NSArray *friends;
@property (assign, nonatomic, getter=isOpen) BOOL open;
+ (instancetype)groupWithDict:(NSDictionary *)dict;
- (instancetype)initWithDict:(NSDictionary *)dict;
@end
---------- CZFriendGroup.m ----------
#import "CZFriendGroup.h"
#import "CZFriend.h"
@implementation CZFriendGroup
+ (instancetype)groupWithDict:(NSDictionary *)dict
{
return [[self alloc] initWithDict:dict];
}
- (instancetype)initWithDict:(NSDictionary *)dict
{
if (self = [super init])
{
[self setValuesForKeysWithDictionary:dict];
NSMutableArray *friendArray = [NSMutableArray array];
for (NSDictionary *dict in self.friends)
{
CZFriend *f = [CZFriend friendWithDict:dict];
[friendArray addObject:f];
}
self.friends = friendArray;
}
return self;
}
@end