Skip to content

Commit fe3e573

Browse files
committed
Dictonary拓展
1 parent a55ef42 commit fe3e573

File tree

5 files changed

+374
-10
lines changed

5 files changed

+374
-10
lines changed

KtTableView/KtTableView.xcodeproj/project.pbxproj

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
E108B2B11CBE191300191E0B /* KtBaseTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = E108B2B01CBE191300191E0B /* KtBaseTableViewCell.m */; };
1515
E108B2B41CBE1C9100191E0B /* KtMainTableViewDataSource.m in Sources */ = {isa = PBXBuildFile; fileRef = E108B2B31CBE1C9100191E0B /* KtMainTableViewDataSource.m */; };
1616
E108B2B71CBE1F6500191E0B /* KtTableViewBaseItem.m in Sources */ = {isa = PBXBuildFile; fileRef = E108B2B61CBE1F6500191E0B /* KtTableViewBaseItem.m */; };
17+
E12A4F5E1CE8180E00AB6F35 /* NSDictionary+KtExtension.m in Sources */ = {isa = PBXBuildFile; fileRef = E12A4F5B1CE8180E00AB6F35 /* NSDictionary+KtExtension.m */; };
18+
E12A4F5F1CE8180E00AB6F35 /* UIView+KtExtension.m in Sources */ = {isa = PBXBuildFile; fileRef = E12A4F5D1CE8180E00AB6F35 /* UIView+KtExtension.m */; };
1719
E1621E021CBDF265003D9438 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = E1621E011CBDF265003D9438 /* main.m */; };
1820
E1621E051CBDF267003D9438 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = E1621E041CBDF267003D9438 /* AppDelegate.m */; };
1921
E1621E081CBDF267003D9438 /* KTMainViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E1621E071CBDF267003D9438 /* KTMainViewController.m */; };
@@ -23,7 +25,6 @@
2325
E1621E1B1CBDF267003D9438 /* KtTableViewTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E1621E1A1CBDF267003D9438 /* KtTableViewTests.m */; };
2426
E1621E261CBDF267003D9438 /* KtTableViewUITests.m in Sources */ = {isa = PBXBuildFile; fileRef = E1621E251CBDF267003D9438 /* KtTableViewUITests.m */; };
2527
E19B41191CC21555008A3E7F /* KtTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E19B41181CC21555008A3E7F /* KtTableViewController.m */; };
26-
E1EE5C9A1CBE791E0095688B /* UIView+KtExtension.m in Sources */ = {isa = PBXBuildFile; fileRef = E1EE5C991CBE791E0095688B /* UIView+KtExtension.m */; };
2728
E1EE5C9D1CBE811C0095688B /* KtBaseTableView.m in Sources */ = {isa = PBXBuildFile; fileRef = E1EE5C9C1CBE811C0095688B /* KtBaseTableView.m */; };
2829
/* End PBXBuildFile section */
2930

@@ -60,6 +61,10 @@
6061
E108B2B31CBE1C9100191E0B /* KtMainTableViewDataSource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KtMainTableViewDataSource.m; sourceTree = "<group>"; };
6162
E108B2B51CBE1F6500191E0B /* KtTableViewBaseItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KtTableViewBaseItem.h; sourceTree = "<group>"; };
6263
E108B2B61CBE1F6500191E0B /* KtTableViewBaseItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KtTableViewBaseItem.m; sourceTree = "<group>"; };
64+
E12A4F5A1CE8180E00AB6F35 /* NSDictionary+KtExtension.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSDictionary+KtExtension.h"; sourceTree = "<group>"; };
65+
E12A4F5B1CE8180E00AB6F35 /* NSDictionary+KtExtension.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSDictionary+KtExtension.m"; sourceTree = "<group>"; };
66+
E12A4F5C1CE8180E00AB6F35 /* UIView+KtExtension.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+KtExtension.h"; sourceTree = "<group>"; };
67+
E12A4F5D1CE8180E00AB6F35 /* UIView+KtExtension.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+KtExtension.m"; sourceTree = "<group>"; };
6368
E1621DFD1CBDF265003D9438 /* KtTableView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = KtTableView.app; sourceTree = BUILT_PRODUCTS_DIR; };
6469
E1621E011CBDF265003D9438 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
6570
E1621E031CBDF267003D9438 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
@@ -78,8 +83,6 @@
7883
E1621E271CBDF267003D9438 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
7984
E19B41171CC21555008A3E7F /* KtTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KtTableViewController.h; sourceTree = "<group>"; };
8085
E19B41181CC21555008A3E7F /* KtTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KtTableViewController.m; sourceTree = "<group>"; };
81-
E1EE5C981CBE791E0095688B /* UIView+KtExtension.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+KtExtension.h"; sourceTree = "<group>"; };
82-
E1EE5C991CBE791E0095688B /* UIView+KtExtension.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+KtExtension.m"; sourceTree = "<group>"; };
8386
E1EE5C9B1CBE811C0095688B /* KtBaseTableView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KtBaseTableView.h; sourceTree = "<group>"; };
8487
E1EE5C9C1CBE811C0095688B /* KtBaseTableView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KtBaseTableView.m; sourceTree = "<group>"; };
8588
/* End PBXFileReference section */
@@ -138,6 +141,17 @@
138141
name = KtBaseTableViewController;
139142
sourceTree = "<group>";
140143
};
144+
E12A4F591CE8180E00AB6F35 /* KtExtension */ = {
145+
isa = PBXGroup;
146+
children = (
147+
E12A4F5A1CE8180E00AB6F35 /* NSDictionary+KtExtension.h */,
148+
E12A4F5B1CE8180E00AB6F35 /* NSDictionary+KtExtension.m */,
149+
E12A4F5C1CE8180E00AB6F35 /* UIView+KtExtension.h */,
150+
E12A4F5D1CE8180E00AB6F35 /* UIView+KtExtension.m */,
151+
);
152+
path = KtExtension;
153+
sourceTree = "<group>";
154+
};
141155
E1621DF41CBDF265003D9438 = {
142156
isa = PBXGroup;
143157
children = (
@@ -163,7 +177,7 @@
163177
E1621DFF1CBDF265003D9438 /* KtTableView */ = {
164178
isa = PBXGroup;
165179
children = (
166-
E1EE5C961CBE78BD0095688B /* KtExtension */,
180+
E12A4F591CE8180E00AB6F35 /* KtExtension */,
167181
E108B2A81CBE148200191E0B /* KtBaseTableViewController */,
168182
E1621E031CBDF267003D9438 /* AppDelegate.h */,
169183
E1621E041CBDF267003D9438 /* AppDelegate.m */,
@@ -208,13 +222,8 @@
208222
path = KtTableViewUITests;
209223
sourceTree = "<group>";
210224
};
211-
E1EE5C961CBE78BD0095688B /* KtExtension */ = {
212225
isa = PBXGroup;
213226
children = (
214-
E1EE5C981CBE791E0095688B /* UIView+KtExtension.h */,
215-
E1EE5C991CBE791E0095688B /* UIView+KtExtension.m */,
216-
);
217-
name = KtExtension;
218227
sourceTree = "<group>";
219228
};
220229
F71B31402A7F180F563A44F9 /* Frameworks */ = {
@@ -406,11 +415,12 @@
406415
isa = PBXSourcesBuildPhase;
407416
buildActionMask = 2147483647;
408417
files = (
418+
E12A4F5E1CE8180E00AB6F35 /* NSDictionary+KtExtension.m in Sources */,
409419
E19B41191CC21555008A3E7F /* KtTableViewController.m in Sources */,
420+
E12A4F5F1CE8180E00AB6F35 /* UIView+KtExtension.m in Sources */,
410421
E108B2B41CBE1C9100191E0B /* KtMainTableViewDataSource.m in Sources */,
411422
E108B2AB1CBE14C300191E0B /* KtTableViewDataSource.m in Sources */,
412423
E108B2B71CBE1F6500191E0B /* KtTableViewBaseItem.m in Sources */,
413-
E1EE5C9A1CBE791E0095688B /* UIView+KtExtension.m in Sources */,
414424
E108B2B11CBE191300191E0B /* KtBaseTableViewCell.m in Sources */,
415425
E1621E081CBDF267003D9438 /* KTMainViewController.m in Sources */,
416426
E1EE5C9D1CBE811C0095688B /* KtBaseTableView.m in Sources */,
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
//
2+
// NSDictionary+KtExtension.h
3+
// KtTableView
4+
//
5+
// Created by baidu on 16/5/15.
6+
// Copyright © 2016年 zxy. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
11+
@interface NSDictionary (KtExtension)
12+
13+
/*!
14+
@brief 根据路径获取obj 例如path为test/xxx/vallue, 会从dict中找到key为test的dict, 在test的dict中找到key为xxx的dict 在xxx的dict中找到key为value的对象
15+
@param path 给定的路径 eg. test/xxx/value
16+
@return 返回obj or nil
17+
*/
18+
- (NSObject *)objectAtPath:(NSString *)path;
19+
20+
/*!
21+
@brief 根据路径获取obj 如果获取不到返回other
22+
@param path 给定的路径
23+
@param other 默认值,当找不到给定的obj,返回other
24+
@return 返回obj or other
25+
*/
26+
- (NSObject *)objectAtPath:(NSString *)path otherwise:(NSObject *)other;
27+
28+
/*!
29+
@brief 判断给定的key值是否为BOOL类型
30+
@param path 给定的路径
31+
@return YES or NO
32+
*/
33+
- (BOOL)boolAtPath:(NSString *)path;
34+
35+
/*!
36+
@brief 判断给定的key值是否为BOOL类型,如果给定的路径中找不到key值,返回other
37+
@param path 给定的路径 @param other 默认值,当找不到给定的obj,返回other
38+
@return 判断结果
39+
*/
40+
- (BOOL)boolAtPath:(NSString *)path otherwise:(BOOL)other;
41+
42+
/*!
43+
@brief 获取给定的key值,返回类型为number
44+
@param path 给定的路径
45+
@return key值 or nil
46+
*/
47+
- (NSNumber *)numberAtPath:(NSString *)path;
48+
49+
50+
/*!
51+
@brief 获取给定的key值,返回类型为number
52+
@param path 给定的路径
53+
@param otherwise 默认值,当找不到给定的obj,返回other
54+
@return key值 or other
55+
*/
56+
- (NSNumber *)numberAtPath:(NSString *)path otherwise:(NSNumber *)other;
57+
58+
59+
/*!
60+
@brief 获取给定的key值,返回类型为String
61+
@param path 给定的路径
62+
@return key值 or nil
63+
*/
64+
- (NSString *)stringAtPath:(NSString *)path;
65+
66+
/*!
67+
@brief 获取给定的key值,返回类型为string
68+
@param path 给定的路径
69+
@param otherwise 默认值,当找不到给定的obj,返回otherwise
70+
@return key值 or otherwise
71+
*/
72+
- (NSString *)stringAtPath:(NSString *)path otherwise:(NSString *)other;
73+
74+
/*!
75+
@brief 获取给定的key值,返回类型为NSArray
76+
@param path:给定的路径
77+
@return key值 or nil
78+
*/
79+
- (NSArray *)arrayAtPath:(NSString *)path;
80+
81+
/*!
82+
@brief 获取给定的key值,返回类型为NSArray
83+
@param path 给定的路径
84+
@param otherwise 默认值,当找不到给定的obj,返回otherwise
85+
@return key值 or otherwise
86+
*/
87+
- (NSArray *)arrayAtPath:(NSString *)path otherwise:(NSArray *)other;
88+
89+
/*!
90+
@brief 获取给定的key值,返回类型为NSMutableArray
91+
@param path:给定的路径
92+
@return key值 or nil
93+
*/
94+
- (NSMutableArray *)mutableArrayAtPath:(NSString *)path;
95+
96+
/*!
97+
@brief 获取给定的key值,返回类型为NSMutableArray
98+
@param path:给定的路径
99+
@param otherwise:默认值,当找不到给定的obj,返回otherwise
100+
@return key值 or otherwise
101+
*/
102+
- (NSMutableArray *)mutableArrayAtPath:(NSString *)path otherwise:(NSMutableArray *)other;
103+
104+
//有类型检查的获取NSDictionary类型 否则返回other
105+
/*!
106+
@brief 通过给定的path获取NSDictionary
107+
@param path:给定的路径
108+
@return key值 or nil
109+
*/
110+
- (NSDictionary *)dictAtPath:(NSString *)path;
111+
112+
/*!
113+
@brief 通过给定的path获取NSDictionary
114+
@param path:给定的路径
115+
@param otherwise:默认值,当找不到给定的obj,返回otherwise
116+
@return key值 or otherwise
117+
*/
118+
- (NSDictionary *)dictAtPath:(NSString *)path otherwise:(NSDictionary *)other;
119+
120+
/*!
121+
@brief 通过给定的path获取NSMutableDictionary
122+
@param path:给定的路径
123+
@return key值 or nil
124+
*/
125+
- (NSMutableDictionary *)mutableDictAtPath:(NSString *)path;
126+
127+
/*!
128+
@brief 通过给定的path获取NSMutableDictionary
129+
@param path:给定的路径
130+
@param otherwise:默认值,当找不到给定的obj,返回otherwise
131+
@return key值 or otherwise
132+
*/
133+
- (NSMutableDictionary *)mutableDictAtPath:(NSString *)path otherwise:(NSMutableDictionary *)other;
134+
135+
/*!
136+
@brief 将当前数据转换为NSData,包含编码格式
137+
@return NSData类型的数据
138+
*/
139+
-(NSData*)data;
140+
141+
@end
142+
143+
#pragma mark NSMutableDictionary接口
144+
///NSMutableDictionary接口
145+
@interface NSMutableDictionary (IDPExtension)
146+
147+
/*!
148+
@brief 安全添加键值对
149+
@param anObject: value
150+
@param forKey:key
151+
*/
152+
- (void)safeSetObject:(id)anObject forKey:(id<NSCopying>)aKey;
153+
154+
/*!
155+
@brief 安全添加键值对
156+
@param anObject: value
157+
@param forKey:key
158+
*/
159+
- (void)safeSetObject:(id)object forKeyedSubscript:(id < NSCopying >)aKey;
160+
161+
/*!
162+
@brief 安全移除key
163+
@param forKey:key
164+
*/
165+
- (void)safeRemoveObjectForKey:(id)aKey;
166+
167+
@end

0 commit comments

Comments
 (0)