BaseDomain.m 1.43 KB
//
//  BaseDomain.m
//  IM_ios_client
//
//  Created by 顾俊生 on 16/1/4.
//  Copyright © 2016年 xiniu. All rights reserved.
//

#import "BaseDomain.h"

@implementation BaseDomain

@synthesize fields;

- (instancetype)init
{
    fields = [NSMutableDictionary new];
    
    return self;
}


#pragma mark - 共同的设置Domain元素的方法
/*
 itemObj:元素值
 itemKey:元素的值在元素所属Domain的字典中对应的Key
 selfFields:元素所属Domain的字典
 selfKey:元素所属Domain的字典在BaseDomain中的Key
 */
-(void)setItemObj:(id)itemObj itemKey:(id<NSCopying>)itemKey selfFields:(NSMutableDictionary *)selfFields selfKey:(id<NSCopying>)selfKey
{
    [selfFields setObject:itemObj forKey:itemKey];
    
    [fields setObject:selfFields forKey:selfKey];
}

#pragma mark - 根据Domain的字典在BaseDomain中的Key获得Domain的字典
-(NSMutableDictionary *)getDomainDicByKey:(NSString *)domainKey
{
    NSMutableDictionary *dic_self = [[NSMutableDictionary alloc]init];
    if ([fields objectForKey:domainKey]) {
        dic_self = [NSMutableDictionary dictionaryWithDictionary:[fields objectForKey:domainKey]];
    }
    return dic_self;
}

#pragma mark - 判读字典中是否存在某个key
-(BOOL)keyExistInDictionary:(NSMutableDictionary *)dic key:(NSString *)key
{
    if (![dic isKindOfClass:[NSNull class]] && dic.allKeys.count > 0 && [[dic allKeys] containsObject:key]) {
        return YES;
    }
    return NO;
}

@end