美文网首页
连续获取字典的key值

连续获取字典的key值

作者: f2efa87f6528 | 来源:发表于2017-06-05 15:02 被阅读53次
    - (id)NsDictValuesForKeyPath:(NSString *)keyPath
    {
        if (keyPath ==nil &&[keyPath isKindOfClass:[NSString class]] && keyPath.length<=0) {
            return nil;
        }
        NSArray *arr = [keyPath componentsSeparatedByString:@"."];
        id tmpDic = nil;
        if (arr && arr.count>0)
        {
            int index = 0;
            tmpDic = self;
            while (tmpDic && index < arr.count) {
                if ([tmpDic isKindOfClass:[NSDictionary class]]) {
                    tmpDic = [tmpDic objectForKey:arr[index]];
                } else {
                    tmpDic = nil;
                    break;
                }
                index++;
            }
        }
        return  tmpDic;
    }
    

    相关文章

      网友评论

          本文标题:连续获取字典的key值

          本文链接:https://www.haomeiwen.com/subject/lepizttx.html